How can I remove object from array, with Lodash?

I'd go for reject() in this scenario. Less code:

var result = _.reject(rooms, { channel: 'room-a', name: 'test' });

require('lodash')()

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.


_.remove() is a good option.

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

_.remove(rooms, {channel: 'room-b'});

console.log(rooms); //[{"channel": "room-a", "name": "test"}]
<script src="https://cdn.jsdelivr.net/lodash/4.14.2/lodash.min.js"></script>