给出了下面的开始,但似乎无法弄清楚如何完成这个。基本上,如果我要调用myTest([one, two, three], 2);
它应该返回元素three
。必须使用for 循环来找到我的解决方案。
function myTest(a, b){
for (let i = 0; i < a.length; i++)
如果我调用myTest([one, two, three], 2);
它应该返回元素three
。
假设以上将是调用它的正确方法。
function myTest(a, b){
for (let i = 0; i < a.length; i++) {
if (a[i] == a[b]) {return a[i]}
}
}
这应该有效。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句