Skythrust Member Jul 9, 2019 130 7 Jun 6, 2023 #1 Hi all, I was wondering if there is an option to combine 2 arrays with an key; Like; JSON1 = '{"id":"1","name":"John", "age":30}'; JSON2 = '{"userid":"1","country":"UK"}'; JSON1.id = JSON2.userid In that case my output could be (John, 30, UK) Thanks!
Hi all, I was wondering if there is an option to combine 2 arrays with an key; Like; JSON1 = '{"id":"1","name":"John", "age":30}'; JSON2 = '{"userid":"1","country":"UK"}'; JSON1.id = JSON2.userid In that case my output could be (John, 30, UK) Thanks!
Adil DevBest CEO May 28, 2011 1,276 713 Jun 6, 2023 #2 in (modern) JS you can spread an object into another e.g. JavaScript: const user = { id: 1, name: 'John Doe' } const activity = { userId: 1, type: 'new_post' } // later on... if (user.id === activity.userId) { const userActivity = { ...user, ...activity } } Upvote 0 Downvote
in (modern) JS you can spread an object into another e.g. JavaScript: const user = { id: 1, name: 'John Doe' } const activity = { userId: 1, type: 'new_post' } // later on... if (user.id === activity.userId) { const userActivity = { ...user, ...activity } }