我有两个数组:
const firstArray = ["A", "B", "1", "2", "F", "89", "8", "K"];
const inputArray = ["1", "B", "F", "A", "89"];
随着
for (const index of firstArray.keys()) {
console.log(index);
}
我从我的数组中获取键值: 0, 1, 2, 3, 4, 5, 6, 7, 8
然后使用
for (const index of inputArray .keys()) {
console.log(index);
}
我从输入数组中获取键:0、1、2、3、4。
我使用这个来比较并检查是否所有元素都在第一个数组中:
const foundedArray = inputArray.filter(element => firstArray.includes(element));
所有内容都很好,但现在我需要将第一个数组中的键获取到我的输入数组中,使它们与第一个数组中相匹配的值相对应。
我需要将第一个数组中的键获取到我的输入数组中:
Value ["1", "B", "F", "A", "89"];
Keys 2, 1, 4, 0, 5
我在这里遇到了困难,该如何编写代码。
playground: https://jsfiddle.net/alaber/u792gdfa/
谢谢!