I’m trying to check if string matches any of the strings saved in database, but with the code I have right now it checks only the first one My code:
JavaScript
x
6
1
for (const key in keys) {
2
if (keys[key].key !== hashedQueryKey) {
3
return "Invalid Key provided.";
4
} else return true;
5
}
6
Advertisement
Answer
You should not return
if the key does not match as you want to continue comparing keys. Something like:
JavaScript
1
9
1
function queryMatches(keys, hashedQueryKey) {
2
for (const key in keys) {
3
if (keys[key].key === hashedQueryKey) {
4
return true;
5
}
6
}
7
return false;
8
}
9