40
39

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 5 years have passed since last update.

Javascriptでin_array的なことをするならsomeメソッドが便利

Posted at
var tmp = ['test', 'hoge', 'Hello', 'world'];

tmp.some(function(v){ return v === 'Hello' }) //-> true
tmp.some(function(v){ return v === 'hello' }) //-> false

some仕様

tmp.some(function(v, i, a){ console.log(v) })
->test
->hoge
->Hello
->world

tmp.some(function(v, i, a){ console.log(i) })
->0
->1
->2
->3

tmp.some(function(v, i, a){ console.log(a) })
->["test", "hoge", "Hello", "world"]
->["test", "hoge", "Hello", "world"]
->["test", "hoge", "Hello", "world"]
->["test", "hoge", "Hello", "world"]

二つの配列を比較

var a = ['test', 'hoge', 'hello', 'world'];
var b = ['aaa', 'bbb', 'ccc', 'hoge'];
a.some(function(v){ return b.some(function(vv){ return vv == v }) }); 
->true
40
39
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
40
39

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?