-4
I would like a help for a function, where I have to know if two objects have the same values, even if in different positions.
In this case they have the same values. I’ve seen how to do with arrays, which is to use a sort
and then compare the values, but what if they are objects? Do you know any method?
**Updating ** Personal I apologise, I saw now the answers and edited.
Example:
let arr1 = [{id:1, idade:5},{id:2, idade:10},{id:3, idade:15},{id:4, idade:20}];
let arr2 = [{id:4, idade:20},{id:1, idade:5},{id:3, idade:15},{id:2, idade:10}];
Thank you!
But in case you would have an Object Array, right?
– Lucas Módolo
You will need a property that is able to distinguish objects, as a unique identifier for each object (usually named
id
). Please [Dit] your question to clarify your problem a little more. And about thesort
, there are more efficient solutions.– Luiz Felipe