How to find the array index with a value?
问题 Say I\'ve got this imageList = [100,200,300,400,500]; Which gives me [0]100 [1]200 etc. Is there any way in JavaScript to return the index with the value? I.e. I want the index for 200 , I get returned 1 . 回答1: You can use indexOf: var imageList = [100,200,300,400,500]; var index = imageList.indexOf(200); // 1 You will get -1 if it cannot find a value in the array. 回答2: For objects array use map with indexOf : var imageList = [ {value: 100}, {value: 200}, {value: 300}, {value: 400}, {value: