Logo

Programming-Idioms

History of Idiom 12 > diff from v48 to v49

Edit summary for version 49 by :
[JS] Code > comments

Version 48

2016-10-19, 11:59:39

Version 49

2016-10-29, 02:04:28

Idiom #12 Check if list contains a value

Check if list contains a value x.
list is an iterable finite container.

Illustration

Idiom #12 Check if list contains a value

Check if list contains a value x.
list is an iterable finite container.

Illustration
Extra Keywords
array vector
Extra Keywords
array vector
Code
list.indexOf(x)
Code
list.indexOf(x) !== -1
Comments bubble
Where list is an Array object. Result is -1 if the object doesn't exist, otherwise its index into the list.
Doc URL
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf