Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
195
rated 0 times [  200] [ 5]  / answers: 1 / hits: 17685  / 8 Years ago, sun, august 21, 2016, 12:00:00

I am looking at the lodash documentation for remove() and I am not sure how to use it.



Say I have an array of Friends,



[{ friend_id: 3, friend_name: 'Jim' }, { friend_id: 14, friend_name: 'Selma' }]



How do you remove friend_id: 14 from the array of Friends?


More From » arrays

 Answers
3

You can use filter.



var myArray = [1, 2, 3];

var oneAndThree = _.filter(myArray, function(x) { return x !== 2; });

console.log(allButThisOne); // Should contain 1 and 3.


Edited: For your specific code, use this:



friends = _.filter(friends, function (f) { return f.friend_id !== 14; });

[#60964] Thursday, August 18, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
byrondonavanc

Total Points: 675
Total Questions: 107
Total Answers: 105

Location: Peru
Member since Fri, Oct 14, 2022
2 Years ago
byrondonavanc questions
;