JavaScript数组显示最低编号的索引
我们需要编写一个包含数字数组的JavaScript函数。然后,该函数应返回数组中最小数字的索引。
示例
为此的代码将是-
const arr = [3, 56, 56, 23, 7, 76, -2, 345, 45, 76, 3];
const lowestIndex = arr => {
const creds = arr.reduce((acc, val, ind) => {
let { num, index } = acc;
if(val < num){
num = val;
index = ind;
};
return { num, index };
}, {
num: Infinity,
index: -1
});
return creds.index;
};
console.log(lowestIndex(arr));输出结果
控制台中的输出-
6
热门推荐
10 小学种植祝福语大全简短
11 十一周岁祝福语简短
12 药材广告祝福语大全简短
13 孩子日常祝福语大全简短
14 祝愿高考成绩祝福语简短
15 理财公司新春简短祝福语
16 结婚祝福语简短霸气的
17 开心早上祝福语简短英语
18 妹妹搬家简短祝福语大全