VOOZH about

URL: https://www.geeksforgeeks.org/javascript/lodash-_-remove-method/

⇱ Lodash _.remove() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Lodash _.remove() Method

Last Updated : 2 Sep, 2024

Lodash _.remove() method is used to remove all elements from the array that predicate returns True and returns the removed elements in an array.

Syntax:

_.remove(array, [predicate]);

Parameters:

  • array (Array) parameter holds the array that needs to be modified.
  • function(Function) parameter holds the function that is invoked per iteration.

Return Value:

  • It returns an array of removed elements.

Example 1: In this example, we are removing and returning the even numbers by using the _.remove() method.

Output:

Original Array [ 1, 3, 5 ]
Removed element array [ 2, 4 ]

Example 2: In this example, we are removing and returning the vowels by using the _.remove() method.

Output:

Original Array [ 'b', 'c', 'd', 'f', 'g', 'h' ]
Removed element array [ 'a', 'e', 'i' ]

Example 3: In this example, we are removing and returning the integers by using the _.remove() method.

Output:

Original Array [ 'a', 'b', 5.6, 'e', 'g', 10.8 ]
Removed element array [ 1, -7, 4 ]
Comment