Answers for "8.3.1. Common Array Methods // concat Examples"

0

8.3.1. Common Array Methods // concat Examples

//The general syntax for this method is:
arrayName.concat(otherArray1, otherArray2, ...)

/*This method adds the elements of one array to the end of another. 
The new array must be stored in a variable or printed to the screen, 
because concat does NOT alter the original arrays.*/

let arr = [1, 2, 3];
let otherArray = ['M', 'F', 'E'];
let newArray = [];

newArray = arr.concat(otherArray);
console.log(newArray);

newArray = otherArray.concat(arr);
console.log(newArray);

console.log(arr.concat(otherArray, arr));

console.log(arr);

//[1, 2, 3, 'M', 'F', 'E']
//[ 'M', 'F', 'E', 1, 2, 3 ]
//[ 1, 2, 3, 'M', 'F', 'E', 1, 2, 3 ]
//[1, 2, 3]
Posted by: Guest on June-16-2021

Code answers related to "8.3.1. Common Array Methods // concat Examples"

Code answers related to "Javascript"

Browse Popular Code Answers by Language