add first element of array javascript code example
Example 1: get first 10 items of array javascript
const list = ['apple', 'banana', 'orange', 'strawberry']
const size = 3
const items = list.slice(0, size)
Example 2: js add element to front of array
var numbers = ["2", "3", "4", "5"];
numbers.unshift("1");
Example 3: unshift method in javascript
var name = [ "john" ];
name.unshift( "charlie" );
name.unshift( "joseph", "Jane" );
console.log(name);
[" joseph "," Jane ", " charlie ", " john "]
Example 4: insert element at beginning of array javascript
const array = [3, 2, 1]
const newFirstElement = 4
const newArray = [newFirstElement].concat(array)
console.log(newArray);
Example 5: javascript get first element of array
let mylist = ['one','two','three','last'];
mylist[0],mylist[1],mylist[2],mylist[3];