0
我試圖用對象創建一個關聯數組,鍵應始終爲字符串(但它們總是數字)。 這是我如何保存它們(記錄用戶點擊):無法用STRING鍵創建數組
App.Recording[currentTime.toString()] = {sound: buttonName.toLowerCase() };
當試圖做到這一點:
var save = {};
save.recording = App.Recording;
console.log(JSON.stringify(save));
我得到這個:
{"recording":[null, null,{"sound":"e"},null,null,null,.......,null,null,null,null,{"sound":"e"},....,null, null...]}
因此,toString()
不起作用在currentTime.toString()
,這使我的數組存儲currentTime
作爲數字,而不是...
如何保存對象並創建關聯數組?