I'd like to merge 2 arrays of objects in Javascript, the source array is something like:
padding = [{'t': 1, 'c': 0}, {'t': 2, 'c': 0}, {'t': 3, 'c': 0}]
data = [{'t': 3, 'c': 5}]
The result should look like:
result = [{'t': 1, 'c': 0}, {'t': 2, 'c': 0}, {'t': 3, 'c': 3}]
Please note that data is being populated into padding by matching 't'. I've tried various method, such as jQuery $.extend({}, padding, data), however it doesn't output correctly.
Appreciate if you share something. Thanks.
Edit 1 (10 April 2020)
As @codemaniac pointed out, I had a typo, the result should be:
result = [{'t': 1, 'c': 0}, {'t': 2, 'c': 0}, {'t': 3, 'c': 5}]
Additional (10 April 2020)
I have padding length of 1000, for data, it should be the subset of padding by the key 't'.
I am looking for efficient way of "merging" and "replacing" the data into padding, some call it "addition", given that padding will always padded with 'c': 0 for every object.
I don't mind to try out lodash JS utility if it's possible.
{'t': 3, 'c': 3}?data = [{'t': 4, 'c': 5}]andpadding = [{'t': 1, 'c': 0}, {'t': 2, 'c': 0}, {'t': 3, 'c': 0}]?