Fábio Zangirolami Fábio Zangirolami - 2 months ago 35x
Node.js Question

How can I remove object from array, with lodash?

i'm trying to remove an object from an array using LoDash.

in server.js (NodeJS)

var lodash = require('lodash')();

var rooms = [
{ channel: 'room-a', name: 'test' },
{ channel: 'room-b', name: 'test' }

i'm go trying with two command and not work:

var result = lodash.find(rooms, {channel: 'room-a', name:'test'});
var result = lodash.pull(rooms, lodash.find(rooms, {channel: 'room-a', name:'test'}));

in console.log(result):

LodashWrapper {
__wrapped__: undefined,
__actions__: [ { func: [Function], args: [Object], thisArg: [Object] } ],
__chain__: false,
__index__: 0,
__values__: undefined }

Can someone help me? Thank you!


Calling the lodash function (by ()) creates a LoDash object that wraps undefined.

That's not what you want; you want the lodash function itself, which contains static methods.

Remove that.