So I'm trying to figure out how to execute a function if all of the if/else statement are false. Below is a snippet of code that I'm currently working that checks the value within the object using a for loop
to iterate each object then checks the key/pair
value technology
.
If all of the statement are false it should return or execute the function noMatch
The current snippet executes the function noMatch
for every else statement. Is there a way to just execute it once if none of the values matched?
$(document).ready(function() {
let object = [
{
"planId": "1",
"technology": "LTE@Home"
},
{
"planId": "2",
"technology": "LTE@Home"
},
{
"planId": "54",
"technology": "home-prepaid-wifi"
},
{
"planId": "0",
"technology": "XTreme Prepaid",
}
];
let technology = "lte-technology";
let dataObject = object;
function match() {
console.log("match");
}
function noMatch() {
console.log("no match");
}
for (let key in dataObject) {
let obj = dataObject[key];
if(technology == obj.technology) {
return match()
} else {
return noMatch()
}
}
});