来源:https://www.w3cplus.com/javascript/javascript-tips.html
1、确保数组的长度
在处理网格结构时,如果原始数据每行的长度不相等,就需要重新创建该数据。为了确保每行的数据长度相等,可以使用Array.fill来处理:
let array = Array(5).fill(\'\'); console.log(array); > Result: (5) ["", "", "", "", ""]
2、数组映射
不使用Array.map来映射数组值的方法。
const array = [
{ name: \'大漠\', email: \'w3cplus@hotmail.com\' },
{ name: \'Airen\', email: \'airen@gmail.com\' }
]
const name = Array.from(array, ({ name }) => name)
> Result: (2) ["大漠", "Airen"]