array.unshift in javascript
//The unshift() method adds one or more elements to the beginning of an array
//and returns the new length of the array.
const array1 = [1, 2, 3];
console.log(array1.unshift(4, 5));
// expected output: 5
console.log(array1);
// expected output: Array [4, 5, 1, 2, 3]// 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);
Also in JavaScript:
- anagram program in javascript
- call laravel route js
- get value in maps loop using enzym
- javascript on script loaded
- flutter reorder map by key
- resize image react native
- angular injector.create example
- settimeout in angular
- es6 array sum javascript
- threejs
- javascript get the last element of an array
- componentWillUnmount functional component for asynchronous requests
- javacript detect undefined
- javascript canvas 1px line
- hrtime to milliseconds
- expressjs create encrypted password
- react cheat sheets
- axios response.json
- javascript max characters string function
- jquery selected label option
- row append and calculation in jquery datatable
- import angular flex layout
- loopback not null
- function para mter js