Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

array.shift()

//Array.shift() removes the first array element and returns it value
//example 1
const array1 = [1, 2, 3];
const firstElement = array1.shift();
console.log(array1);
// expected output: Array [2, 3]
console.log(firstElement);
// expected output: 1

//example 2

var arr = ["f", "o", "o", "b", "a", "r"]; 
arr.shift(); 
console.log(arr); // ["o", "o", "b", "a", "r"]
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
8+5 =