Answer the question
In order to leave comments, you need to log in
How do you usually combine 2 entities into one?
I don’t know how you can ask a question correctly, so I’ll try to explain with an example.
The API of some services returns, for example, entries and users in 2 different arrays:
{
posts: [
{
user_id: 1,
title: 'Заголовок записи #1'
text: 'Текст записи #1'
},
...
],
users: [
{
id: 1,
fullname: 'Пол Аллен'
},
...
]
}
var usersWithIdIndex = [];
for(var i in response.users) {
usersWithIdIndex[response.users[i].id] = response.users[i];
}
for(var i in response.posts) {
response.posts[i]['user'] = users[response.posts[i].user_id];
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question