Skip to content Skip to sidebar Skip to footer

How To Set Array Index Of Normalized Data

I am trying to normalize a dataset, update an array index, and then denormalize the data. I'd like to change a P.O. at on a header line and have the change propagate to a linked or

Solution 1:

I think the issue is in this line.

data[i]['items'][j]['order'] = data[i]['order']; // Set default header

change this to

data[i]['items'][j]['order'] = { ...data[i]['order'] }; // Set default header

Reason: In Javascript the objects are assigned by reference. Thus the order object was referenced in both the items. When you spread it, then it unpacks the properties into the new object created by the object literal, making a shallow copy.

Post a Comment for "How To Set Array Index Of Normalized Data"