Answer the question
In order to leave comments, you need to log in
How to compare two arrays of objects and output the difference?
Greetings, there is such a task from two different databases, the rest of the goods are unloaded:
var office = [
{ name: "Карандаш", qt: 1, code: 3 },
{ name: "Ручка", qt: 20, code: 4 }
],
sklad = [
{ name: "Карандаш", qt: 1, code: 3 },
{ name: "Ручка", qt: 3, code: 4 }
];
Answer the question
In order to leave comments, you need to log in
1. I didn't understand. If you do not know what you need from the comparison, then how can we help you? If all this will be done by a separate person, then why is there a question and generally requirements for the code?
2. Sort the array by unique data (in your case, by code or product name) and connect the elements. It's hard to explain in words, but I can try if necessary. You can try lodash, they answered another question
3. And why then questions 1 and 2? No, I don’t know similar ones, due to the fact that completely different requirements can be applied to the comparison. But, perhaps, something lodash will satisfy your requirements.
4. Pay attention to the incoherence in your question.
5. Didn't decide.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question