javascript add new array element to start of array
var colors = ["white","blue"];
colors.unshift("red"); //add red to beginning of colors
// colors = ["red","white","blue"]// 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:
- sweet alert react
- fonction fleche javascript
- js is undefined or null
- vs code is showing 5k untracked files when nothing is changed from last commit
- how to remove text style on td in angularjs
- action checkbox selected vue js
- nuxt vuetify google fonts
- jquery clear file input
- how to deploy react app firebase
- react grid
- chart.js line chart
- httpclient post c# json
- inheritance in javascript
- how to validate file extension in javascript
- jquery number format comma
- how to change the tab text in React
- founder of javascript
- postfix date javascript
- how to change css variable in javascript
- js errors
- scrollto angular
- button click event listener angular
- API requests return index.html in production
- jquery validation plugin