Tech Junkie Blog - Real World Tutorials, Happy Coding!: JavaScript Array Methods: Array.concat() Method

Monday, April 30, 2018

JavaScript Array Methods: Array.concat() Method

The Array.concat() method returns a array that is a concatenation of the original array and what what is being passed into the concat() method.  The concat() method can take either values or another array.

For example lets say you have an array of numbers from 1 to 3

var numbers = [1,2,3];

Now let's say you want to concatenate the numbers 4 and 5 into the array.  You would type in the following

numbers.concat(4, 5);

The resulting array would be 1,2,3,4,5

or you can concatenate two arrays together, for example lets say you already declared the numbers array with the values 1,2,3 and you want to concatenate another array call numbers2 with the values 4,5,6 you can call the concat() method like the following

var numbers2 = [4,5,6];

1 comment:

  1. I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts.

    business analytics training in vizag


Search This Blog