Resizing


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)];
}


© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext