我的问题如下:如何使用i获取数组元素的位置?
我只需要使用 2 个功能。
第一个函数请求元素,调用第二个函数并显示位置。
第二个函数在数组中查找元素并返回该元素的位置。
// Simple array with 5 elements.
var x = ["a","b","c","d","e"];
first_function(); // The call for the first function
function first_function(){
const result = prompt("Search the word");
document.write(i);
second_function();
}
function second_function(x){
let i = 0;
while ( i < 5 ){
if (x[i] == result){
return i;
i++
}
}
aluckdog
慕容708150
温温酱
相关分类