JavaScript - Append Array At The Beginning Of Another Array Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Here are the various approaches to append an array at the beginning of another array in JavaScriptUsing unshift() Method - Most CommonUses the unshift() method to add elements of a2 at the beginning of a1 using the spread operator. JavaScript let a1 = [ 4, 5, 6 ]; let a2 = [ 1, 2, 3 ]; a1.unshift(...a2); console.log(a1); Output[ 1, 2, 3, 4, 5, 6 ] Using concat() MethodThe concat() method creates a new array without modifying the existing arrays. JavaScript let a1 = [ 4, 5, 6 ]; let a2 = [ 1, 2, 3 ]; let result = a2.concat(a1); console.log(result); Output[ 1, 2, 3, 4, 5, 6 ] Using Spread OperatorCreates a new array by spreading elements of a2 first, followed by a1. JavaScript let a1 = [ 4, 5, 6 ]; let a2 = [ 1, 2, 3 ]; let result = [...a2, ...a1 ]; console.log(result); Output[ 1, 2, 3, 4, 5, 6 ] Using splice() MethodModifies the original array in-place. It inserts elements of a2 at the beginning of a1 using splice() with 0 as the start index. JavaScript let a1 = [ 4, 5, 6 ]; let a2 = [ 1, 2, 3 ]; a1.splice(0, 0, ...a2); console.log(a1); Output[ 1, 2, 3, 4, 5, 6 ] Using for LoopIt iterates over a2 in reverse order, adding each element to the start of a1 using unshift(). JavaScript let a1 = [ 4, 5, 6 ]; let a2 = [ 1, 2, 3 ]; for (let i = a2.length - 1; i >= 0; i--) { a1.unshift(a2[i]); } console.log(a1); Output[ 1, 2, 3, 4, 5, 6 ] Which Approach to Use?unshift() Method: Use this when you need to modify the original array directly and you want a simple and quick solution. It is efficient for small arrays but may have performance impacts for larger arrays due to frequent element shifting.concat() Method: Best for creating a new array without altering the original ones. Ideal for situations where immutability and data integrity are important.Spread Operator (...): Recommended for concise, readable code when creating new arrays. It’s great when you don’t want to mutate existing arrays and prefer modern JavaScript syntax.splice() Method: Useful when you need to insert elements at specific positions in an array. Be cautious, as it modifies the original array.for Loop: Offers flexibility and manual control over how elements are added. It’s useful when complex logic or condition checks are needed during the addition. Create Quiz Comment S souravsharma098 Follow 0 Improve S souravsharma098 Follow 0 Improve Article Tags : JavaScript Web Technologies javascript-array JavaScript-DSA JavaScript-QnA +1 More Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)8 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like