1

I hope my terminology is correct on the title.

I have a fiddle of my code:

https://jsfiddle.net/v3yatpx8/

This is giving me undesirable results. You can see from the console.log(newArray) .

I want to push attMap into "info" for prodMap and have my final array structured like this:

[
   {
      "info" : [
      	{
           "attribute":"Grade:",
           "value":"Premium OR-Grade"
        },
        {
         "attribute":"Disposable or Reusable:",
         "value":"Reusable"
      	},
        {
         "attribute":"Handle:",
         "value":"Finger Rings"
      	},
      ],
      "name":"Product 1",
      "sku":"4242"
   }
]

I'm really not sure how to accomplish this. Any help would be appreciated!

1 Answer 1

1

Your object.assign statement is just a bit off.

newArray = prodMap.map((itm, i)=> ({
  ...itm,
  info: attMap[i]
}));

Map the array, keep each itm, and override its info property.

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.