1.

Explain what are detection mutation methods and array detection non-mutation methods? List three array detection mutation methods and two array detection non-mutation methods with their uses?

Answer»

Mutation methods ALTER the original array.  

Following are the list of array mutation methods that initiate VIEW updates 

  • push() - is used to ADD an element to the end of an array 
  • pop() - is used to remove the last element of an array 
  • shift() - is used to remove the first element of an array. 
  • unshift() - adds an element at the beginning of an array. 
  • splice() - is used for various purposes 
    • insert an element at the specified index 
    • replace one or multiple elements in an array 
    • remove an element from the selected index 
  • sort() - is used to sort an array in ascending ORDER 
  • reverse() - is used to reverse an array 

Below are the methods that don't mutate the original array but return a new array and are CALLED non-mutation methods.  

  • filter() - Used to filter array within the given condition 
  • contact() - To combine two arrays and add elements to the last array element 
  • slice() - Returns a copy of a portion of an array 


Discussion

No Comment Found

Related InterviewSolutions