Array in JS
Array related notes
const list = [1, 2, 3 ];
push(element) will add an element in the last position of the array.
input: list.push(4)
output: [1, 2, 3, 4]
pop() will remove an element from the last position of an array.
input: list.pop()
output: [1, 2, 3]
unshift() method will add an element to the starting point of the element of the array.
input: list.unshift(5)
output: [5, 1, 2, 3]
shift() method will remove an element from the starting point of the element of the array.
input: list.shift()
output: [1, 2, 3]
slice(start, end) method will slice a portion of an array from start and end-1.
It is always a good practice to add the same type of data in the array.
Last updated