remove first 3 elements from array javascript code example

Example 1: remove first element from array javascript

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.shift();

Example 2: remove first element from array javascript

const array1 = [1, 2, 3];

const firstElement = array1.shift();

console.log(array1);
// expected output: Array [2, 3]

console.log(firstElement);
// expected output: 1

Example 3: remove first element of array javascript

var fruits = ["Banana", "Orange", "Apple", "Mango"]
fruits.shift()

Example 4: delete from array javascript

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];var removed = arr.splice(2,2);/*removed === [3, 4]arr === [1, 2, 5, 6, 7, 8, 9, 0]*/

Example 5: javascript array remove first

// example (remove the last element in the array)
let yourArray = ["aaa", "bbb", "ccc", "ddd"];
yourArray.shift(); // yourArray = ["bbb", "ccc", "ddd"]

// syntax:
// <array-name>.shift();

Example 6: js array.splice first element

var indexToRemove = 0;
var numberToRemove = 1;

arr.splice(indexToRemove, numberToRemove);