2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[javascript]2つのarrayで完全一致と部分一致

Posted at

たまに使いたくなるけど、書き方忘れるので備忘録。

変数
const baseArray = [1,2,3,4,5,6,7,8,9,10]
const target1   = [10,9,8,7,6,5,4,3,2,1]
const target2   = [1,2,3]
const target3   = [11]
完全一致(every)
baseArray.every((num) => target1.includes(num))
> true

baseArray.every((num) => target2.includes(num))
> false

baseArray.every((num) => target3.includes(num))
> false
部分一致(some)
baseArray.some((num) => target1.includes(num))
> true

baseArray.some((num) => target2.includes(num))
> true

baseArray.some((num) => target3.includes(num))
> false

参考

2
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?