-1

I have an object like

let arr = [
    {isManaged: true, id:1},
    {isManaged: false, id:2},
    {isManaged:false, id:3}
]

to get the values which are true, i do

arr.map(shift => ({
    id: shift.id,
    isPartnerManaged: shift.isManaged,
}))

but this will only return me the values where i true, now, I want to remove them from the array of objects. I tried to use the array.pop but i don't know what index to feed it. Any ideeas?

Chris
  • 155
  • 4
  • 11
  • please add the wanted result as well. – Nina Scholz Jun 13 '19 at 12:07
  • 1
    Possible duplicate of [Filter an array based on an object property](https://stackoverflow.com/questions/35231008/filter-an-array-based-on-an-object-property) – str Jun 13 '19 at 12:08

2 Answers2

3

arr = arr.filter(shift => shift.isManaged);

horia
  • 419
  • 4
  • 17
-1

You could filter the array and build new objects.

var array = [{ isManaged: true, id: 1 }, { isManaged: false, id: 2 }, { isManaged: false, id: 3 }],
    result = array
        .filter(({ isManaged }) => isManaged)
        .map(({ isManaged: isPartnerManaged, id }) => ({ id, isPartnerManaged }));

console.log(result);
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392