we have an object called options. I wanted to append in options those values, which are not present from object2 based on id.
options
0: {value: '642a60e2573c9d004b041407', label: 'label1', mapped: true}
1: {value: '642a60e2573c9d004b041408', label: 'label2', mapped: true}
2: {value: '642a60e2573c9d004b041409', label: 'label3', mapped: true}
3: {value: '642a60e2573c9d004b04140a', label: 'label4', mapped: true}
4: {value: '642a60e2573c9d004b04140b', label: 'label5 ', mapped: true}
5: {value: '642a60e2573c9d004b04140c', label: 'label6', mapped: true}
object2 =
642a60e2573c9d004b04140a: {id: '642a60e2573c9d004b04140a', createdAt: '2023-04-03T05:15:14.316Z', myApiName: null, abel: null}
642a60e2573c9d004b04140b: {id: '642a60e2573c9d004b04140b', createdAt: '2023-04-03T05:15:14.316Z', myApiName: null, abel: null}
642a60e2573c9d004b04140c: {id: '642a60e2573c9d004b04140c', createdAt: '2023-04-03T05:15:14.316Z', myApiName: null, abel: null,}
642a60e2573c9d004b04140d: {id: '642a60e2573c9d004b04140d', createdAt: '2023-04-03T05:15:14.316Z', myApiName: null, abel: null, }
642a60e2573c9d004b04140e: {id: '642a60e2573c9d004b04140e', createdAt: '2023-04-03T05:15:14.317Z', myApiName: null, abel: null, }
642a60e2573c9d004b04140f: {id: '642a60e2573c9d004b04140f', createdAt: '2023-04-03T05:15:14.317Z', myApiName: null, abel: null, }
642a60e2573c9d004b041407: {id: '642a60e2573c9d004b041407', createdAt: '2023-04-03T05:15:14.315Z', myApiName: null, abel: null, }
642a60e2573c9d004b041408: {id: '642a60e2573c9d004b041408', createdAt: '2023-04-03T05:15:14.316Z', myApiName: null, abel: null, }
642a60e2573c9d004b041409: {id: '642a60e2573c9d004b041409', createdAt: '2023-04-03T05:15:14.316Z', myApiName: null, abel: null, }
642a6123573c9d0024a992f2: {id: '642a6123573c9d0024a992f2', createdAt: '2023-04-03T05:16:19.896Z', myApiName: null, abel: null, }
Since, I am new to JS, any help would be appreciated.
Expected result:
options
0: {value: '642a60e2573c9d004b041407', label: 'label1', mapped: true}
1: {value: '642a60e2573c9d004b041408', label: 'label2', mapped: true}
2: {value: '642a60e2573c9d004b041409', label: 'label3', mapped: true}
3: {value: '642a60e2573c9d004b04140a', label: 'label4', mapped: true}
4: {value: '642a60e2573c9d004b04140b', label: 'label5 ', mapped: true}
5: {value: '642a60e2573c9d004b04140c', label: 'label6', mapped: true}
6: {value: '642a6123573c9d0024a992f2', label: 'label7', mapped: true}
7: {value: '642a60e2573c9d004b04140d', label: 'label5 ', mapped: true}
8: {value: '642a60e2573c9d004b04140e', label: 'label6', mapped: true}
9: {value: '642a60e2573c9d004b04140f', label: 'label7', mapped: true}```
2
Answers
You can map over the options object and add elements from the other object. This might solve your problem.
I found this solution, which is working, you can refer this.