【问题标题】:how to get a element index number using element of an array in JavaScript [closed]如何使用JavaScript中的数组元素获取元素索引号[关闭]
【发布时间】:2022-01-04 15:56:10
【问题描述】:

假设这是我的数组

 `const arr=['a','b','c','d','e','f','g']`

如何获取'e'的索引号

【问题讨论】:

标签: arrays indexing element indexof


【解决方案1】:

你可以使用Array.prototype.indexOf:

const array = ["apples", "bananas", "oranges"];
const orangesIndex = array.indexOf("oranges");
console.log(orangesIndex) // 2
console.log(array[orangesIndex]) // "oranges"

【讨论】:

    猜你喜欢
    • 2013-09-14
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 2019-08-15
    • 1970-01-01
    • 2011-04-16
    • 2020-03-10
    相关资源
    最近更新 更多