我有這樣的陣列:
[
0: {barcode: '4124121241241', qty: 1}
1: {barcode: '1234124135134', qty: 1}
2: {barcode: '3573424625234', qty: 1}
3: {barcode: '2346468457354', qty: 1}
4: {barcode: '5684452043432', qty: 1}
5: {barcode: '1241263475686', qty: 5}
6: {barcode: '1231241231423', qty: 15}
]
我正在推動這樣的人:
shelfArray.push({
[rafName]:JSON.parse(results.rows.item(index).BarcodeArray)
});
這是我的輸出:
0:
Q1:
BarcodeArray: [{…}]
1:
Q2:
BarcodeArray: (7) [{…}, {…}, {…}, {…}, {…}, {…}, {…}]
2: {Q3: null}
但我想要這樣:
Q1:
BarcodeArray: [{…}]
Q2:
BarcodeArray: (7) [{…}, {…}, {…}, {…}, {…}, {…}, {…}]
2: {Q3: null}
怎么能這樣做?
uj5u.com熱心網友回復:
與其創建shelfArray為陣列[],不如將其創建為空物件
const shelfArray = {}; // rather than `= [];`
然后在回圈時向該物件添加鍵,而不是使用括號表示法推送:
shelfArray[rafName] = JSON.parse(results.rows.item(index).BarcodeArray);
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/463778.html
標籤:javascript 反应式
下一篇:eslint不檢測解構變數
