Skip to content

Instantly share code, notes, and snippets.

@ashraf267
Created July 1, 2022 15:47
Show Gist options
  • Save ashraf267/3395393e18236251ca6d7a8ce342cf5e to your computer and use it in GitHub Desktop.
Save ashraf267/3395393e18236251ca6d7a8ce342cf5e to your computer and use it in GitHub Desktop.
custom JS code to search through an array
let colors = ["red", "green", "blue", "yellow"];
let favColor = "pink";
(function check() {
let output = 0;
for(color in colors) {
// console.log(colors[color]);
if(colors[color] == favColor) {
output = "I found your favorite color, color " + colors[color];
break;
}
}
isNaN(output) ? console.log(output) : console.log("Unknown currency");
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment