You're writing a function that removes an element from an array without mutating the original array and returns the new array. Which array method could help you achieve this?
- filter()
- splice()
- pop()
- push()
The filter() method creates a new array with all elements that pass the test implemented by the provided function, making it a suitable choice for removing elements from an array without changing the original array. The splice() method can be used for removing elements but mutates the original array. pop() and push() are used for adding/removing elements from the end of an array.
Loading...
Related Quiz
- The ________ operator can be used to compare both value and type in JavaScript.
- Which array method adds elements to the beginning of an array?
- In JavaScript, the _________ property is a reference to an object from which the current object inherits properties.
- Which of the following scenarios is NOT recommended for using arrow functions?
- Unlike function expressions, function declarations are _________.