Append More Elements To An Array In JavaScript
Here we consider how to append more elements to an array in javascript.
Lets start with one example here.
Suppose we have an array inside javascript as shown here.
var array = [ "1" , "2" , "3" ];
We wants to append one or more elements, you can use array.push() method.
push() method adds one or more elements to the end of an array.
var array = [ "1" , "2" , "3" ];
array.push( "4", "5" );
Result will be ["1" , "2" , "3" , "4" , "5" ]
For appending one array to another, we can use array.concat() method.
var array1 = [ "1" , "2" , "3" ];
var array2 = [ "4" , "5" , "6" ];
array1.concat( array2 );
Result will be ["1" , "2" , "3" , "4" , "5" , "6" ]