如何从数组集中返回索引 - 1。
例如:
Function demo(Id) {
Const ids= [1, 2, 3,4,5] ;
// how can I read current index and return index - 1.
return id;
}
Function demo1 (id) ;
最佳答案
您可以通过 indexOf 函数来完成此操作,请参见下文...
function demo(id) {
const ids= [1, 2, 3,4,5] ;
var index = ids.indexOf(id);
var res = i - 1;
return res;
}
关于javascript - 如何从数组集中返回索引 - 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59139784/