push vs concat vs spread

push, con­cat and spread all of them are object/array manip­u­la­tion methods.

push — mutates the orig­i­nal data

var a = [1, 2, 3];
a.push(9); // returns 4 
console.log (a); // [1, 2, 3, 9]

con­cat — returns new array and does not mutate the orig­i­nal data

var a = [1, 2, 3];
a.concat(9); // returns [1, 2, 3, 9]
console.log(a); // returns [1, 2, 3]

spread — nicer way to use con­cat, does not mutate the orig­i­nal data

var a = [1, 2, 3];
console.log([...a, 9]); // returns [1, 2, 3, 9]

You may also like...