好的,所以有两个数组。另一个是二维的,就像这样:
const locations = [
['London', 60.205490, 24.655899],
['Rome', 60.294411, 25.040070],
['Berlin', 60.262800, 24.824730],
['New York', 60.1698557, 24.9383791],
['Paris', 60.629951, 24.858080],]
const cities = ['London', 'Paris', 'Berlin' ]
我如何比较两个数组以获得如下结果:
const indexArr = [0, 4, 2]
答案 0 :(得分:-1)
我认为您正在尝试获得如下结果:
const locations = [
['London', 60.205490, 24.655899],
['Rome', 60.294411, 25.040070],
['Berlin', 60.262800, 24.824730],
['New York', 60.1698557, 24.9383791],
['Paris', 60.629951, 24.858080],]
const cities = ['London', 'Paris', 'Berlin' ]
let temp = [];
cities.forEach(function(someItem, someIndex){
locations.forEach(function(item, index){
if(item.indexOf(someItem) >= 0) {
temp.push(index);
}
})
})
console.log(temp);