在pel数组中查找特定元素的位置或索引的方法是什么

lewis 2016-08-27 20次阅读

您可以使用indexOf()方法来查找特定元素在pel数组中的位置或索引。

例如,如果您想要查找元素"apple"在pel数组中的位置,可以使用以下代码:

var pel = ["banana", "apple", "orange", "grape"];
var index = pel.indexOf("apple");

console.log(index); // 输出结果为 1,表示"apple"在数组中的位置为1

如果pel数组中不存在要查找的元素,indexOf()方法将返回-1。



发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。