📅  最后修改于: 2022-03-11 15:03:46.898000             🧑  作者: Mango
// Quick way
a = ['A','B','C','D'];
console.log(a.length); // 4
a.length = 3;
console.log(a); // ['A', 'B', 'C'];
// Proper way
function resize(arr, newSize, defaultValue) {
return [ ...arr, ...Array(Math.max(newSize - arr.length, 0)).fill(defaultValue)];
}