0
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 1 year has passed since last update.

【JavaScript】【jQuery】配列同士の検索 some()の中でincludes()

Last updated at Posted at 2023-02-09

コールバック関数は最強

コード some ※OR条件

process.stdin.resume();
process.stdin.setEncoding('utf8');

var data = [3, 5, 4, 2, 7];
var search_1 = [1,6];
var search_2 = [1,3];
var search_3 = [2,7];
var search_4 = [2];

var result = search_1.some((v) => data.includes(v));
console.log(result);

var result = search_2.some((v) => data.includes(v));
console.log(result);

var result = search_3.some(function(v){return data.includes(v)});
console.log(result);

var result = search_4.some(function(v){return data.includes(v)});
console.log(result);

結果

false
true
true
true

コード every ※AND条件

var arr = [3, 5, 8];
var item_1 = [3,5];
var item_2 = [1,5];
var item_3 = [5];
var result = item_1.every(function(v){return arr.includes(v)});
// ↓これでもOK
console.log(result);
var result = item_2.every((v) => arr.includes(v));
console.log(result);
var result = item_3.every((v) => arr.includes(v));
console.log(result);

結果

true
false
true
0
0
0

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
0
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?