js數(shù)組的contains方法 JS實現(xiàn)判斷數(shù)組是否包含某個元素示例?
JS實現(xiàn)判斷數(shù)組是否包含某個元素示例?您可以搜索indexof,如果沒有,返回-1。代碼示例:let arr=[1,2,undefined,“l(fā)istening to the wind is the
JS實現(xiàn)判斷數(shù)組是否包含某個元素示例?
您可以搜索indexof,如果沒有,返回-1。
代碼示例:
let arr=[1,2,undefined,“l(fā)istening to the wind is the wind”,“echo”
//use indexof to find the subscript feature
let result=排列索引(“聽風(fēng)就是風(fēng)”//3
if(result>-1){
//做點什么…]}