-2
Good morning, everyone,
I have two objects. In one of them I have only id. In the other several fields, the id of this first object and the name. I need to somehow scan object 2 to find the same id that’s on the first object to know its name, because I only have the id.
//objeto 1
$rootScope.obj1 = result.data.value;
//objeto 2
obj2 = result.data.value;
Example of how it looks in the browser console:
//obj1
Object {id: 2, createdAt: "2017-12-22T14:01:35.225", updatedAt: "2017-12-22T14:01:35.225", name: "abc", initialDate: "2017-12-22"…}
//obj2
Object {......id: 2}
Thanks for your cooperation
If you’re manipulating one
array
of objects, only useindexOf
to find the position where to display the name. https://www.w3schools.com/jsref/jsref_indexof_array.asp– Saymon Souza
I realized that I can only actually compare objects if I do the fixed position: if (obj1[1]. id === obj2[1]. id)
– user100894