Multiple JSON arrays with key

Skythrust

Member
Jul 9, 2019
133
7
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
714
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 }
}
 

Users who are viewing this thread

Top