JavaScript array exists and is an element exists

1, determination method
let arr1 = [1,2,3]
let res = Array.isArray(arr1) // true
 

  

2, to determine whether there is an element

Includes () method is used to determine whether an array contains a specified value, if so returns true, otherwise false.

 
[1, 2, 3].includes(2);     // true
[1, 2, 3].includes(4);     // false
[1, 2, NaN].includes(NaN); // true
 

  - from: www.caigouganhuo.club

 

Guess you like

Origin www.cnblogs.com/agen-su/p/11832796.html