The push() method ads one ore more elements to the rnd of array [1,2,3] and returns the new length of the array.
arr.push([element1[, ...[, elementN]]])
Parametres are ElementN - which elements to push to the end
Return property is the new length of the object upon which method is called.
The method is generic and coul be called with apply() and call() on objects resembling arrays. The push() method is relying on length property to determine, where to insert new numbers. If length cannot be converted into number - the index of start is 0. This includes the possibility of length being nonexistent, in which case length will also be created.
The only native array-like object are STRINGS, but the method cannot be applied to them as they are IMMUTABLE;
/*-------------------------------------------Basic Example---------------------------------*/
var numbers = [1, 2, 3];
numbers.push(4);
console.log(numbers); // [1, 2, 3, 4]
numbers.push(5, 6, 7);
console.log(numbers); // [1, 2, 3, 4, 5, 6, 7]
/*--------------------------------------------Length and push--------------------------------------------*/
var sports = ['soccer', 'baseball'];
var total = sports.push('football', 'swimming');
console.log(sports); // ['soccer', 'baseball', 'football', 'swimming']//изменяется sports
console.log(total); // 4//Тотал выдает новую длинну, и только, ему не присваевается значение sports
/*-----------------------------------Using push fo MERGING arryas=---------------------*/
var vegetables = ['parsnip', 'potato'];
var moreVegs = ['celery', 'beetroot'];
// Merge the second array into the first one
// Equivalent to vegetables.push('celery', 'beetroot');
Array.prototype.push.apply(vegetables, moreVegs);// apply делает наши ерреи аргументами, с которыми работает push()
console.log(vegetables); // ['parsnip', 'potato', 'celery', 'beetroot']