我真的很掙扎于 javascript 數組和對象。我需要創建這個結構(數組?或..?不確定它是什么), data = [ 12, 24, 13, 21]從數組動態獲取 Chart.js 圖表。該數組創建為yAxisArray.push(singularYaxisDataArray);在哪里var singularLabelArray = [];singularLabelArray has values 12, 24, 13, 21 pushed into it.并且 'yAxisArray' 中可能有多個 singleLabelArray ,這意味著迭代它們以創建其中幾個結構“data = [ 12, 24, 13, 21]”以放入其中var datasources = [ { label: "Budgeted", backgroundColor: 'red', data: [12, 24, 13, 21] }, { label: "Actual", backgroundColor: "#8e5ea2", data: [408, 547, 675, 734] } ];迭代 yAxisArray 不是問題,但無法從中獲取我需要的結構。for (idx = 0; idx < yAxisArray.length; idx++) { var datasources = { label: labelArray[idx], **data: yAxisArray[idx],** backgroundColor: colorsList[idx], } }謝謝
如何從多維數組創建 [ 12,24, 13,21]
慕尼黑8549860
2023-09-21 17:32:33