We can apply few methods on array in order to remove or add any values. we can use pop(), push(), shift(), unshift().
// * methods on array
const countries = ["swiss", "UK", "france"];
// * Pushes the element to last
countries.push("Italy")
// * Unshift adds to begining of element
countries.unshift("Iceland")
// * Pop removes the last element
countries.pop();
// * shift removes the first element
countries.shift();
console.log(countries);
The join()
method also joins all array elements into a string. It behaves like this,
syntax:
variablename.join(' * ');
const countries = ["swiss", "UK", "france"];
console.log(countries.join(' * ');
Using delete may leave undefined holes in the array. You can delete an element using delete
keyword,
syntax:
delete variableName;
const countries = ["swiss", "UK", "france"];
console.log(delete countries[0]);
The splice()
method can be used to add new items to an array. It has two parameters,
syntax:
splice(start, deleteCount, item1, item2, itemN)