for (const item of array) { obj[item] = `this is ${item}`; } console.log(obj);
你覺得答案會是哪個?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// 第一種 { '1': 'this is 1', '2': 'this is 2', '3': 'this is 3', '4': 'this is 4', '5': 'this is 5' } // 第二種 { '5': 'this is 5' '4': 'this is 4', '3': 'this is 3', '2': 'this is 2', '1': 'this is 1', }