数组示例:
$scope.numbers=['AA','AB','AC'];
如何从数组中随机选择一个项目?
假设您实际上在使用数组,这是如何执行此操作的示例:
var arr = ['AA', 'AB', 'BB'];
function rand() {
// get a random index
var randIndex = Math.floor(Math.random() * arr.length);
return arr[randIndex];
}
// run it ten times:
for (var i = 0; i < 10; i++) {
console.log(rand());
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句