比方說,我有兩個數組:的javascript:從連接兩個數組
var meals: ["breakfast", "lunch", "dinner"];
var ingredients: [["eggs", "yogurt", "toast"],["falafel", "mushrooms", "fries"], ["pasta", "cheese"];
是否有一個優雅的解決方案創建JavaScript對象的數組,其特點:
var dailySchedule = {"breakfast" : ["eggs", "yogurt", "toast"],
"lunch": ["falafel", "mushrooms", "fries"],
"dinner": ["pasta", "cheese"]
}
我知道它應該是與.reduce的東西,但我一直在撓我的頭怎麼辦...
使用'的(...)'循環:) – BeNdErR
JSON是文本數據,你所追求的是簡單的JavaScript對象。 – vlaz