I need to create a new object key/value. In it i need the values from the already existing key/value object and i need to add values that are only in the array.
The array:
[{ name: "Computer", name: "Car", name: "House", name: "Flower"}]
The object key/value:
{ computer: { title: 'Computer', color: 'Black' }, house: { title: 'House', color: 'Red' }}
So in this case the new object would need to be:
{ computer: { title: 'Computer', color: 'Black' }, car: { title: 'Car', color:'' }, house: { title: 'House', color: 'Red' }, flower: { title: 'Flower', color:'' } }
What is the easiest way to achieve this? I was thinking to loop over the array compare the values between them and extract the repeating ones, but i'm not sure how to do that.
computeris arbitrary? Are1and2meant to be literal keys corresponding to … what, the array index plus one? Is thenamekey arbitrary? I would have expected{title: "name"}or something. I am very confused!"car"key seems to come out of nowhere. Could you please spell out the relationship? Maybe post a few more examples of input/output?carkey seems to come out of nowhere. Could you please spell out the relationship? Maybe post a few more examples of input/output? From this one example it's difficult to tell which parts are static and which parts are dynamic. Like, do we always copy from thenameproperty of the elements of the array? Or isnamearbitrary and it might be different in another array?