djilea
Last Updated: February 25, 2016
·
3.777K
· thurloat
11748328e57fff12f212fb14df91cbbf

Javascript array mutability

Just a quick reminder to folks that some JS array functions have very
different behaviours and return types.

var x = ['foo', 'bar'];

array.push

x.push('baz');
=> 3 
// returns the index at which the item was inserted.

x
=> ['foo', 'bar', 'baz']
// modifies the array.

array.concat

x.concat('buzz');
=> ['foo', 'bar', 'baz', 'buzz']
// returns a new array with the the arguments combined.

x
=> ['foo', 'bar', 'baz']
// original array is untouched.
Say Thanks
Respond