JavaScript - Insert Multiple Elements in JS Array Last Updated : 15 Nov, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report These are the following ways to insert multiple elements in JavaScript arrays: 1. Using bracket Notation(Simple and Efficient for Small Array)The Bracket can be used to access the index of the given array and we can directly assign a value to that specific index. JavaScript let a = [2, 3, 4]; a[3] = 1; a[4] = 5; console.log(a); Output[ 2, 3, 4, 1, 5 ] 2. Using splice() Method (Efficient for Large Array)The splice() method can be used to insert elements to the given array, as it takes parameter where you have to add the position where you want to insert the element, the number of elements you want to remove(in this cse it is 0 as we are adding elements) and then the value that you want to insert. JavaScript let a = [10, 20, 30, 40]; a.splice(a.length, 0, ...[50, 60, 70]); console.log(a); Output[ 10, 20, 30, 40, 50, 60, 70 ] 3. Using spread Operator(Efficient for Large Array)This method creates a new array to insert elements. The JavaScript spread syntax (...) can be used to add multiple elements in the JS array. we can directly assign the array values to the new array. JavaScript let a1 = [2, 3]; // Inserts 0 at the start let a2 = [0, 1, ...a1]; console.log(a2); // Inserts 4,5 at the end let a3 = [...a1, 4, 5]; console.log(a3); Output[ 0, 1, 2, 3 ] [ 2, 3, 4, 5 ] Comment More infoAdvertise with us Next Article JavaScript - Insert Multiple Elements in JS Array A amit_singh27 Follow Improve Article Tags : JavaScript Web Technologies javascript-array Similar Reads JavaScript - Insert Elements at the End of JS Array To insert elements at the end of a JS array, the JavaScript push() method is used.JavaScriptlet a = [10, 20, 30, 40]; a.push(50); console.log(a);Output[ 10, 20, 30, 40, 50 ] Table of ContentUsing Built-In MethodsWriting Your Own MethodUsing Built-In MethodsThe JavaScript push() method is used to ins 1 min read JavaScript - Insert Element in an array In JavaScript elements can be inserted at the beginning, end, and at any specific index. JS provides several methods to perform the operations.At the Beginning This operation inserts an element at the start of the array. The unshift() method is commonly used, which mutates the original array and ret 2 min read JavaScript - Insert Elements at a Given Position in an JS Array To insert an element at a specific position in a JavaScript array, the JS splice() method is used. JavaScriptlet a = [10, 20, 30, 40]; let e = 50; let i = 2; a.splice(i - 1, 0, e); console.log(a);Output[ 10, 50, 20, 30, 40 ] Table of ContentUsing built-in MethodWriting Your Own MethodUsing built-in 1 min read JavaScript - Insert Elements at the Beginning of JS Array To insert an element at the beginning of a JS array, the JavaScript unshift() method is used.JavaScriptlet a = [1,2,3,4] // Inserting element a.unshift(0) console.log(a)Output[ 0, 1, 2, 3, 4 ] Table of ContentUsing Built-in MethodsWriting Your Own MethodUsing Built-in MethodsThe JS unshift() method 1 min read JavaScript - Inserting Multiple Items at Specific Index in JS Array We can insert an item into Array at a specific index using the JavaScript Array splice method. This method removes the elements from the mentioned index and add items at that specific position.1. Using array.splice() MethodJavaScript array.splice() Method is an inbuilt method in JavaScript that is u 3 min read Like