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?
arr = arr.filter(shift => shift.isManaged);
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.