我想讓我的程序生成一個4位數的引腳用於遊戲。幫助每個循環的Javascript
我本來想這樣做:
function paswdGen() {
var nums = [0, 0, 0, 0];
for each (var x in nums) {
x = Math.floor((Math.random() * 9) + 1);
}
}
document.getElementById("nums").innerHTML = nums;
如何使用「每個」在JavaScript中循環,不jQuery的?
[0,0,0 ,0] .forEach(function(item,index){}); – Lewis 2015-02-05 15:42:58
nums.forEach(function(number){...}); – Mike 2015-02-05 15:43:07
http://stackoverflow.com/questions/9329446/for-each-over-an-array-in-javascript – user1983983 2015-02-05 15:43:33