我有 2 个 javascript 数组:
const arr1 = ['one', 'two', 'three', 'four', 'five', 'six'];
const arr2 = ['five', 'six', 'four', 'three', 'one', 'two'];
PS-我无法更改/控制“arr1”的顺序
我的问题是如何使“arr2”的项目顺序与“arr1”的项目相匹配。
我一直在想它可能看起来像:
//1. Some kind of function to get index of all items
const items = (item) => item === item;
const arr3 = arr1.findIndex(items);
//2. Then think I need to get the values of arr2 using ([Array.values()][1])**
const arr2vals = arr2.values();
//3. Then some kind of calculation that matches the values, this is where I really struggle more, but weak at best lol!
arr3.filter(value => arr2vals.includes(value))
** 参考:MDN
慕容3067478
慕工程0101907
相关分类