-9
A
回答
1
迭代對象屬性並生成結果數組。
var obj = {
"rules": [{"interval": "Week 1","count": 0},{"interval": "Week 2","count": 0}],
"assets": [{"interval": "Week 1","count": 1},{"interval": "Week 2","count": 0}]
};
var res = Object.keys(obj) // get all object keys
.reduce(function(arr, k) { // iterate over keys array and generate result array
obj[k].forEach(function(v) { // iterate over inner property value array
arr.push(Object.assign({ // generate the object element
name: k
}, v));
});
return arr; // return the array reference
}, []);
console.log(res);
+0
運行腳本後得到未定義的不是函數錯誤 – Rakesh
+0
@Rakesh:在哪個瀏覽器中......在舊瀏覽器中,您需要使用polyfill作爲方法 –
相關問題
- 1. D3.js:在折線圖
- 2. D3 js可摺疊圖增加弧線曲線半徑
- 3. d3.js multiseries折線圖工具提示問題
- 4. MPAndroidChart折線圖scrollview重疊
- 5. SSRS:重疊折線圖
- 6. 2D重疊折線圖
- 7. 如何避免重疊的多系列折線圖工具提示d3.js
- 8. D3.js折線圖 - 定位點
- 9. D3 JS折線圖從0開始
- 10. C3.js折線圖 - 軸標籤問題
- 11. D3.js折線折線圖工具提示
- 12. 可摺疊Sankey圖-D3
- 13. GMSURLTileLayer重疊折線
- 14. D3 - 線圖問題
- 15. D3.js組合條形圖和折線圖x軸誤差問題
- 16. 在d3.js的折線圖上重繪網格線(移除並重繪)
- 17. c3.js折線圖數據標籤文本重疊
- 18. ggplot:重疊欄和折線圖
- 19. D3折線圖非脆性
- 20. D3多系列折線圖
- 21. D3折線圖進入bindPopup
- 22. 多線圖D3.js
- 23. D3.js:折線圖 - 工具提示和垂直線懸停
- 24. 問題與D3線圖
- 25. 爲折線圖創建D3工具提示的問題
- 26. 使用D3.js繪製折線圖(股票圖)錯誤
- 27. D3折線圖 - 無法顯示線條
- 28. 摺疊存檔問題
- 29. ExtJs Fieldset摺疊問題
- 30. Mercurial案例摺疊問題
所以遍歷並追加到一個新的陣列 – epascarello
我會推薦給熟悉的['Array'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#Methods_2)和['Object'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object#Methods_of_the_Object_constructor)方法。 – Xufox