-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?

2

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

-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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.