我有一個數組,我需要能夠從它得到2個數組。我需要這兩個數組作爲圖表。圖表組件需要一個標籤數組和一個總數組(每個標籤)。從一個數組創建2個數組ecmascript 2015
我還在學習新的數組方法,的forEach,地圖等於是用我裸,這是數組我有:
const income = [
{
"date": 1482233886000,
"name": "Company A",
"type": "Salary",
"description": "Salary jan. 2017",
"amount": 50.6
},
{
"date": 1482406686000,
"name": "Company B",
"type": "Salary",
"description": "Salary jan. 2017",
"amount": 40.23
},
{
"date": 1485171486000,
"name": "Company A",
"type": "Salary",
"description": "Salary feb. 2017",
"amount": 200.2
},
{
"date": 1485344286000,
"name": "Company B",
"type": "Salary",
"description": "Salary feb. 2017",
"amount": 100.4
},
{
"date": 1490655892000,
"name": "Company A",
"type": "Salary",
"description": "Salary mar. 2017",
"amount": 20
},
{
"date": 1493335850000,
"name": "Company A",
"type": "Salary",
"description": "Salary apr. 2017",
"amount": 15
},
{
"date": 1493335850000,
"name": "Company B",
"type": "Salary",
"description": "Salary apr. 2017",
"amount": 10
}
];
爲了讓我這樣做是爲了得到獨一無二的標籤標籤(說明):
[...new Set(income.map(value => value.description))]
=> ["Salary jan. 2017", "Salary feb. 2017", "Salary mar. 2017", "Salary apr. 2017"]
這工作,但現在我想每一個描述如總量:
//[90.83, 300.6, 20, 25]
如果可能的話,是否有人可以幫助我使用最後一個陣列和ES6風格。我想減少,但我無法得到任何的。所以我希望一個主人可以教我; D。
'const的量= income.map(值=> value.amount)' –
運算 '按組' 求和不量的列表需要一個。 – rasmeister
'forEach'和'map'不是「新」。他們老了」。它們也不是ECMAScript 2015,也就是ES6。他們是ES5。 – 2017-02-28 03:29:24