1. 程式人生 > >js獲取陣列內相同元素的下標

js獲取陣列內相同元素的下標

var findSameIndex = function (nums) {
  var minNum = Math.min.apply(null, nums);
  var dataIndexArr = [];
  for (let i = 0, len = nums.length; i < len; i++) {
    var index = nums.indexOf(minNum);
    delete nums[index];
    if (index == -1) {
      break;
    }
    dataIndexArr.push(index);
   
  }
console.log("dataIndexArr", dataIndexArr) return dataIndexArr; //[3, 4] } findSameIndex([7, 3, 1, 0, 0, 6])