This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Demo showing effect of ellipsis (...) in array push() method | |
arrA = []; | |
arrB = []; | |
out = [{e1: 5}, {e2:10}]; | |
arrA.push(out); //Whole out array will be added as a single element to arrA | |
arrB.push(...out); //Note the usage of ... which will add each element of out as a separate element to arrB | |
for (let i = 0; i < arrA.length; i++) { | |
console.log("arrA[%d]: ", i, arrA[i]); | |
} | |
for (let i = 0; i < arrB.length; i++) { | |
console.log("arrB[%d]: ", i, arrB[i]); | |
} |