First thank you in advance for any responses to this problem I am having. I am new to JS and feel that this code should be pretty straight forward, but it is not working as intended.
I want to search through these objects in the array by name, and if the name (that is obtained through the prompt) is found in the array, I want to display the id of that object.
if I type 'Jef' into the prompt, I get the ID; but if I type 'Steve' or 'Ryan' I get nothing. I also noticed that the loop seems to end no matter what I type without a break being added. I think the loop is breaking, but I don't know what is causing it to break before the 'If' condition is met. Please help!
var array = [{
name: 'Jef',
age: 29,
id: '000'
}, {
name: 'Steve',
age: 28,
id: '001'
},
{
name: 'Ryan',
age: 28,
id: '002'
}
];
var i;
for (i = 0; i < array.length; i++) {
if (prompt() == array[i].name) {
console.log(array[i].id)
}
}