The push() function appends all the arguments in it to the end of the given array. Using this we can modify an existing array. When you call the push() method, it returns the total number of elements in the modified array after it has added the given arguments to the end of the array.
The indexOf() function searches the array for the given element and then returns the index of the element’s first occurrence in the array. The first parameter is the value you want to search in the array and the second parameter is the starting index for the search.
If you do not pass a second parameter then the searching will begin from index 0, which is the default searching index. If the specified element does not exist in the array then the function will return -1.
The forEach() function has no return value and does not change nor return the original array. It is like a loop function that iterates over all the elements in the array. It is often used with other functions like filter(), map() and every(). All of these functions accept a callback function as the first parameter. The second parameter is optional, it is there to specify this value for the callback function.
Note that the original array will be unchanged and the function will return a new array having the elements from the original array from the starting to the ending point but not the element indexed at the endpoint.
The filter() function helps us to filter a collection of elements based on the condition the programmer has provided. This callback is executed for each element in the array. If the callback function returns true then the element is added to a new array. Only the values which suffice the condition are added to the new array. The original array is left unchanged.
The unshift() functionality is the opposite of the shift() function. This function inserts the argument to the beginning of the given array. After using this, all the elements are shifted to the right by one position. This function also modifies the original array.
Thank You for reading! If you have any suggestions or queries, do let us know in the comments.