◼️pop(): Remove an item from the end of an array.
Example:
const numbers =['one','two','three','four','five','six']
//1pop
console.log('the element to be deleted is:'+numbers.pop())
console.log(numbers)
Output:
the element to be deleted is:six
[ 'one', 'two', 'three', 'four', 'five' ]
◼️push(): Add items to the end of an array.
Example:
const numbers =['one','two','three','four','five','six']
//2push
console.log('the element to be inserted is:'+numbers.push('seven'))
console.log(numbers)
Output:
the element to be inserted is:7
[
'one', 'two',
'three', 'four',
'five', 'six',
'seven'
]
◼️shift(): Remove an item from the beginning of an array.
Example:
const numbers =['one','two','three','four','five','six']
//1shift method use to shift or delete the first element of the array
console.log(numbers.shift())
console.log(numbers)
Output:
one
[ 'two', 'three', 'four', 'five', 'six' ]
◼️unshift(): Add items to the beginning of an array.
Example:
const numbers =['one','two','three','four','five','six']
//2unshift method
console.log(numbers.unshift('anything'))
console.log(numbers)
Output:
7
[ 'anything', 'one', 'two', 'three', 'four', 'five', 'six' ]
0 Comments