I just started with programming and I am just trying to access the only last position of element m in array n.The code given below provide the all positions of element m.
var n = [];
while (true) {
let input = prompt("enter number to array");
if (input == null || input == "c") {
break;
}
n.push(Number(input));
console.log(n);
}
var m = prompt("enter number to be match");
console.log(m)
for (var i = 0; i < n.length; i++) {
if (n[i] == m) {
console.log(i);
}
}
Aucun commentaire:
Enregistrer un commentaire