My task involves working with an array of objects where each time I select a value, it gets pushed into the array. My goal is to merge two objects that share the same key "code" and remove any empty values.
(4) [{…}, {…}, {…}, {…}]
0: {code: "abc", value: "", access: "A"}
1: {code: "abc", value: "ok", access: ""}
2: {code: "def", value: "xyz", access: ""}
3: {code: "def", value: "", access: "B"}
The desired output should be:
(2) [{…},{…}]
0: { code: "abc", value: "ok", access: "A"}
1: {code: "def", value: "xyz", access: "B"}
I have attempted using the spread operator but it seems to not work as expected. Any suggestions or help would be greatly appreciated.