Professional Documents
Culture Documents
Rupam Js Array-Methode
Rupam Js Array-Methode
Syntax
array.shift()
const fruits = ["Banana", "Orange", "Apple", "Mango"];
console.log(fruits);
fruits.shift();
console.log(fruits);
o/p:-
"Orange", "Apple", "Mango"
unshift()
The unshift() method adds new elements to the beginning of an array.
const fruits = ["Banana", "Orange", "Apple", "Mango"];
console.log(fruits);
fruits.unshift("Lemon","Pineapple");
console.log(fruits);
o/p:- "Lemon","Pineapple","Banana", "Orange", "Apple", "Mango"
splice()
The splice() method adds and/or removes array elements.
Syntax
array.splice(index, howmany, item1, ....., itemX)
Parameter Description
index Required.
The position to add/remove items.
Negative value defines the position from the end of the array.
howmany Optional.
Number of items to be removed.
Example1:-
console.log(fruits);
Example2:-
fruits.splice(2, 2);
console.log(fruits);