0

I receive something like this:

serverDocument.scheduledLines [

{ _id: 'd375d9f136d9aed8161e874b', resourceId: '54cc874716368a9be973d0cb', workOrderId: '53yc4SeHRErSaWZcr',

}, { _id: '4136758377e2a0b89fcd15fb', resourceId: '54cc874716368a9be973d0cb', workOrderId: 't3cdTGDpxhm6sue5Z',

}, { _id: '691cda0327a2b947bc40c008', resourceId: '54cc874716368a9be973d0cb', workOrderId: 'mzP5asqiMEKcYpPW9',

},]

I try to remove every resourceId element with serverDocument.scheduledLines.slice(0, 1), but in stead of removing the resourceId's, the second element is removed. Is it possible to remove the resourceId in one level deeper?

1 Answer 1

2

You can just remove the property from each array item with a map function

const array = [
    { _id: 'd375d9f136d9aed8161e874b', resourceId: '54cc874716368a9be973d0cb', workOrderId: '53yc4SeHRErSaWZcr',},
    { _id: '4136758377e2a0b89fcd15fb', resourceId: '54cc874716368a9be973d0cb', workOrderId: 't3cdTGDpxhm6sue5Z',},
    { _id: '691cda0327a2b947bc40c008', resourceId: '54cc874716368a9be973d0cb', workOrderId: 'mzP5asqiMEKcYpPW9',},
]

// removing the resourceId
array.map((item) => {
    delete item.resourceId;
    return item;
});

console.log(array);

Thats because in your attempt you don't manipulate the items in the array, you just manipulate the array itself.

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

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.