js数组的contains方法 JS实现判断数组是否包含某个元素示例?

JS实现判断数组是否包含某个元素示例?您可以搜索indexof,如果没有,返回-1。代码示例:let arr=[1,2,undefined,“listening to the wind is the

JS实现判断数组是否包含某个元素示例?

您可以搜索indexof,如果没有,返回-1。

代码示例:

let arr=[1,2,undefined,“listening to the wind is the wind”,“echo”

//use indexof to find the subscript feature

let result=排列索引(“听风就是风”//3

if(result>-1){

//做点什么…]}