将二维数组转化为对象的形式
转之前的数据:
转之后:
javascript
const entries = new Map([
['foo', 'bar'],
['baz', 42],
['beginNode', '202212151048010054'],
['beginNode', '202212151048447710'],
]);
console.log(entries)
const obj = Object.fromEntries(entries);
console.log(obj);
// expected output: Object { foo: "bar", baz: 42, beginNode: "202212151048447710" }
New Map 将会是无重复的数据,重复key取后一个
eg:
javascript
/*newArr :[]*/
const newList = []
newArr.forEach(item => {
const entries = new Map(item)
newList.push(Object.fromEntries(entries))
})
将数组中的每n项分为一组并重组数组
javascript
let n = 3
for (let i = 0; i < oldArr.length; i += n) {
newArr.push(oldArr.slice(i, i + n))
}