在javascript数组indexOf()方法中以1开始索引是否重要?



为什么w3school在这个程序中添加+1 ?结果显示苹果在1个索引,为什么要加1呢?………

<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Array.indexOf()</h2>
<p id="demo"></p>
<script>
const fruits = ["Apple", "Orange", "Banana", "Mango"];
let position = fruits.indexOf("Apple") +1;
document.getElementById("demo").innerHTML = "Apple is found in position " + position;
</script>
</body>
</html>

当我删除+1时,它显示苹果的索引是0,这对我来说是有意义的。

w3school在演示的最后加上+ 1,表示苹果位于数组的第一个位置。如果去掉+1,程序将显示第一次出现的实际索引"Apple"在数组中,如预期的那样为0。