I am currently dealing with an array of objects in Javascript where I need to verify if a certain value exists within any object and return the corresponding id. The issue arises when using the some()
function as it only seems to match the first object.
The array in question is structured as follows:
const testObj = [
{id: 1, nombre: "Juan"},
{id: 2, nombre: "María"},
{id: 3, nombre: "Pedro"}
];
This is my current approach:
let test = 'María'
let priority;
testObj.some(item => item.nombre === test ? priority = item.id : priority = 7)
However, upon checking the result, it yields:
console.log(priority) // 7
I'm puzzled as to why it fails to return the accurate id when the specified value does exist within one of the objects. Any insights on this behavior?