In JavaScript, how is the best way to code a way to check if a value exists in an array of data?
Here is what I currently have:
var html = [];
html.push({
key: "/1/1.html",
value: "html 1 data"
});
if(doesKeyExist(html, "/1/1.html"))
{
alert(getValue(html, "/1/1.html"));
}
function doesKeyExist(arr, key)
{
$.each(arr, function (index, data) {
if(data.key === key)
return true;
});
return false;
}
function getValue(arr, key)
{
$.each(arr, function (index, data) {
if(data.key === key)
return data.value;
});
}
The above code does not alert the value of "html 1 data", and no error is shown in the console.
May I please have some help with the above code?
Thanks