返回长度内的索引

eg:

changeLimit () {
  function getArrayItems(arr, num) {
    const temp_array = [];
    for(let index in arr) {
      temp_array.push(arr[index]);
    }
    const return_array = [];
    for (let i = 0; i<num; i++) {
      if(temp_array.length>0) {
        const arrIndex = Math.floor(Math.random()*temp_array.length);
        return_array[i] = temp_array[arrIndex];
        temp_array.splice(arrIndex, 1);
      } else {
        break;
      }
    }
    return return_array;
  }
  this.randomMovieList = getArrayItems(this.movieList, 5);
}

2、splice

temp_array.splice(arrIndex, 1),

删除temp_array中下标为arrIndex的那个元素

相关文章:

  • 2021-04-27
  • 2021-11-30
  • 2021-12-30
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2021-08-29
猜你喜欢
  • 2022-12-23
  • 2022-02-13
  • 2021-07-15
  • 2022-12-23
  • 2021-11-30
  • 2021-06-01
  • 2021-11-01
相关资源
相似解决方案