可以用數組的indexof函數,方法arr.indexof(find,start);find:要找的內容,必須;start:查找開始下標,可選;返回:查找數據所在的下標,如果沒找到,返回-1如果只要知道是否有8這個數字,直接調用arr.indexof(8),如果返回值不為-1,說明找到了vars=[1,2,3,5,6,9];varu=s.indexof(5);//返回5所在的下標3vard=s.indexof(8);//返回-1console.log(u);console.log(d);
js 數組查詢:js數組套對象[朗讀]
@mtrang
頂0
加入收藏
相關問答推薦