1. 生成随机数组
const randomArray = [];
const length = 10;
for (let i = 0; i < length; i++) {
  randomArray.push(Math.floor(Math.random() * length));
}
  1. 遍历并去重
const uniqueArray = [];
randomArray.forEach((item) => {
  if (!uniqueArray.includes(item)) {
    uniqueArray.push(item);
  }
});
console.log(uniqueArray);
js给几个随机数组使它遍历并且去重

原文地址: https://www.cveoy.top/t/topic/YY3 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录