Horje
javascript push item to beginning of array Code Example
javascript push item to beginning of array
var colors = ["white","blue"];
colors.unshift("red"); //add red to beginning of colors
// colors = ["red","white","blue"]
push element to array to first place js
let arr = [4, 5, 6]

arr.unshift(1, 2, 3)
console.log(arr);
// [1, 2, 3, 4, 5, 6]
insert element at beginning of array javascript
// Use unshift method if you don't mind mutating issue
// If you want to avoid mutating issue
const array = [3, 2, 1]

const newFirstElement = 4

const newArray = [newFirstElement].concat(array) // [ 4, 3, 2, 1 ]

console.log(newArray);




Javascript

Related
javascript add new array element to start of array Code Example javascript add new array element to start of array Code Example
js push to start of array Code Example js push to start of array Code Example
reference body js Code Example reference body js Code Example
js loop backwards Code Example js loop backwards Code Example
for of with index Code Example for of with index Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11