arrays-methods

This class is all about array methods in Javascript

  • This method is used to add an element to the end of an array.
  • This method is used to remove the last element of an array.

Array.shift()

  • This method is used to remove the first element of an array.

Array.unshift()

  • This method is used to add an element to the beginning of an array.

Array.splice()

  • This method is used to add or remove elements from an array.

Array.slice()

  • This method is used to return a shallow copy of a portion of an array into a new array object.

Array.concat()

  • This method is used to merge two or more arrays.

Array.join()

  • This method is used to join all elements of an array into a string.
  • This method determines whether an array contains a certain value among its entries.

Array Desctructuring

  • This method is used to return specific properties of an array.

For example:

const array = ["banana", "computer", "iphone"];
const [fruit, , mobile, ...rest] = array;

Array Spread Operator

  • This operator (...something) is another way of copy an array to new array object
const array = ["Hi", "there", "!"];
const newCopyArray = [...array];

console.log(newCopyArray);
  • This creates a new array populated with the results of calling a provided function on every element in the calling array.
  • This method sorts the elements of an array in place and returns the sorted array.

  • image