numbers = [1,2,3,4,5];
function doubling(number) {
number *= 2;
return number;
}
obj = {};
for (var i = 0; i < numbers.length; i++)
doubled = doubling(numbers[i]);
obj[numbers[i]] = doubled;
console.log(obj);
当我运行我的代码时,它会打印“10”,而我想要它打印 {1:2, 2:4, 3:6, 4:8, 5:10}。为什么会这样?