我有一个具有以下值的javascript数组,
let arr = ["2","4","6","8","10"];
我有第二个有三个整数的数组,
let index = [1,5,9];
我如何使用jQuery(或Javascript)来使用数组从arr获取索引,并将其添加到新数组中。我想将这些字符串添加到新数组中。
indexArr = ["1","3","5"]
由于
答案 0 :(得分:-1)
$(document).ready(function(){
var arr = ["2","4","6","8","10"];
var index = ["1","5","9"];
var arrIndex = index.map(function(value){
return arr.indexOf(value);
})
console.log(arrIndex);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>