Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save IacovColisnicenco/6cec56185964eed9678aa67c45ebaa09 to your computer and use it in GitHub Desktop.
Save IacovColisnicenco/6cec56185964eed9678aa67c45ebaa09 to your computer and use it in GitHub Desktop.
searchElem, indexOf, function
let arr = [1, 2, 3, 4];
let arg = prompt("input your number", "0");
if (arg != null) {
searchElem(arg);
} else {
console.log("Cancel was pressed");
}
function searchElem(arg){
let res = arr.indexOf(+arg);
if (res == -1) {
console.log("Num not found");
} else {
console.log(res);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment