Find Names by idsi have two arrays want to find names by their ids.
person: [ {id: 1, name: 'abc'}, {id: 2, name: 'xyz'}, {id: 3, name: 'pqr'}, ]data: [ {id: 1, personId: [1,2,3]}, {id: 2, personId: [1,3]}, {id: 3, personId: [1,2]},]
Expected Output:
personId: [1,2,3] return // abc,xyz,pqrpersonId: [1,3] return // abc,pqrpersonId: [1,2] return // abc,xyz
I am using react-native.
I have tried this:
for (let person of this.state.data) { for (let personName of person['personId']){ let name = this.state.person.find(nme => nme['id'] === personName); alert(name); } }
Any help would be greatly appreciated