Sure it's a stupid mistake but can't see what I'm doing wrong here but when I test in my fiddle I can't get a result, could someone point out where I'm going wrong please?
In the code below and in the fiddle I'm trying to return the value for array id: 15.
https://jsfiddle.net/wc71ra6r/3/
Code
function findValueById(myA, fVal) {
for(var i = 0; i < myA.length; i++){
if(myA[i].id === fVal) {
return myA[i].value;
}
}
}
var myArray = [{id: 10, value: 100},
{id: 15, value: 300},
{id: 20, value: 200];
alert(findValueById(myArray, 15)); // 300
}to the last element in array. jsfiddle.net/tusharj/wc71ra6r/4