JavaScript在另一个数组中查找嵌套数组
我有一个数组
a = [ [1,2],[3,4] ]
b = [1,2]
,我想查找 b 是否在 a 中,我该怎么做?
我尝试使用
a.includes(b)
or
a.find(e => e == b)
但两者都不起作用
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与 <代码>一些 。如果内部阵列的长度与
检查内部阵列
b
的长度不匹配,请立即返回false,否则使用incover
b 。这也将检查何时
[2,1]
等元素何时出现。Iterate over
a
withsome
. If the length of the inner array doesn't match the length ofb
immediately return false, otherwise useevery
to check that the inner arrayincludes
all of the elements ofb
. This will also check when elements are out of order like[2, 1]
should you need to do so.