JavaScript Lodash filter and omit lodash filter exclude,lodash filter out,lodash filter or

Is there a way I can filter on an array, but omit certain key:values using lodash? For example:

var people = [{
    _id: 0,
    name: 'Joe',
    type: 1
}, {
    _id: 1,
    name: 'James',
    type: 2
}, {
    _id: 2,
    name: 'Mary',
    type: 0
}, {
    _id: 3,
    name: 'Clark',
    type: 0
}];

var people_with_type_0 = _.filter(people, { 'type': 0 });

// so people_with_type_0 now contains the following
var people_with_type_0 = [{
    _id: 2,
    name: 'Mary',
    type: 0
}, {
    _id: 3,
    name: 'Clark',
    type: 0
}];

The above is brilliant, but I want to omit the type?

Answer:1

people_with_type_0 can be pass through _.map() to get the objects without 'type' property:

var array = _.map(people_with_type_0, function(person) {
  return _.omit(person, 'type');
});
console.log(array);

This prints:

[ 
  { _id: 2, name: 'Mary' }, 
  { _id: 3, name: 'Clark' } 
]
Answer:2
_.map(_.filter(people,{type : 0}),_.partial(_.omit,_,'type'))
Answer:3

I have a marquee on my website: <marquee>Hello! <span id="text">Welcome to my website.</span></marquee> I want to change dynamically the content of the span with id="text" ...

I have a marquee on my website: <marquee>Hello! <span id="text">Welcome to my website.</span></marquee> I want to change dynamically the content of the span with id="text" ...

I read that Object.gePrototypeOf(someObject) returns the prototype of the passed object and aPrototype.isPrototypeOf(someObject) returns true if aPrototype is the prototype of someObject. It is ...

I read that Object.gePrototypeOf(someObject) returns the prototype of the passed object and aPrototype.isPrototypeOf(someObject) returns true if aPrototype is the prototype of someObject. It is ...

I'm currently working on my website footer and would like it if the user clicks Contact Us that a yellow div appears from behind the footer. Here is what I'm working on so far right now, but I can't ...

I'm currently working on my website footer and would like it if the user clicks Contact Us that a yellow div appears from behind the footer. Here is what I'm working on so far right now, but I can't ...

  1. slideup effects in jquery
  2. slideup in jquery
  3. slideup() in jquery
  4. slideup function in jquery

AngularJS $scope.model is undefined when I initialize it via Javascript <button ngf-select="upload($file)">Выбрать</button> <span id="photoSpan"></span> ...

AngularJS $scope.model is undefined when I initialize it via Javascript <button ngf-select="upload($file)">Выбрать</button> <span id="photoSpan"></span> ...

  1. angularjs scope model
  2. angularjs scope ng-model
  3. angularjs scope contains the model data