How to use Array concat() Method In Javascript
The JavaScript Array concat() Method is used to merge two or more arrays together. This method helps to add new elements at the beginning of the array.
Example: The below example implements the concat() method to add element at the start of an array.
const arr = [23, 45, 12, 67];
console.log(`Array Elements Before
element addition:
${arr}`);
console.log(`Array Elements After
element addition:
${[32].concat(arr)}`);
Output
Array Elements Before element addition: 23,45,12,67 Array Elements After element addition: 32,23,45,12,67
Add new elements at the beginning of an array using JavaScript
In this article, we will learn how to add new elements at the beginning of an array using JavaScript. We can do this by using the following methods:
Table of Content
- Using the Array unshift() method
- Using array.splice method
- Using the Spread operator
- Using Array concat() Method
- Using array destructuring
Contact Us