0

enter image description here

I have this JSON array. I am displaying data in a table. So, How should I put 'transactionData' inside the main object? i.e. I want the object as

{
completeTime: "value",
createTime: "value2",
assigneeName:"value3",
assigneeMap:"value4"
}

Since this is a JSON Array, so I need a way to iterate the array and make each of the objects as required.

I can't use the original JSON array since the object transactionData is not fixed and its keys might change. So, I don't want to hardcode any value like assigneeMap or assigneeName as it might change. Hence, I want whatever the values in transactionData object are there, I want to insert it into my main object.

4
  • why can't you use the original json array? please provide more relevant code Commented Jun 24, 2020 at 19:35
  • use array.map() Commented Jun 24, 2020 at 19:36
  • @depperm I have updated my question. Commented Jun 24, 2020 at 19:37
  • Does this answer your question? How can I access and process nested objects, arrays or JSON? Commented Jun 24, 2020 at 19:42

2 Answers 2

1

use the array.map(), something like this

results.map(x=>{
{
completeTime: x.completeTime,
createTime: x.createTime,
assigneeName: x.assigneeName || x.assigneename,
assigneeMap:x.assigneeMap || x.assigneeMap || x.yourChangedKey,
}
})
Sign up to request clarification or add additional context in comments.

Comments

0

Use Array.prototype.map()

const result = arr.map(item => {
    const { completeTime, createTime, data: { transactionData } } = item;
    const { assigneeName, assigneeMap } = transactionData;
    return {
        completeTime,
        createTime,
        assigneeName,
        assigneeMap
    }
});

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.