This the Json Object
var data = [
{anioTtile: "2018", anioData:[10000,0,20000,0,0,0,0,0,0,0,0,0]},
{anioTtile: "2018", anioData:[10000,0,20000,0,50000,0,5000,5000,0,0,0,0]},
{anioTtile: "2017", anioData:[10000,0,0,0,0,0,0,0,0,0,0,0]},
{anioTtile: "2017", anioData:[10000,0,20000,0,0,0,0,0,0,0,0,0]},
{anioTtile: "2017", anioData:[10000,0,20000,0,50000,0,5000,5000,0,0,0,0]}
]
This is the JavaScript function that I use:
var anios = {};
var resultado = data.filter(function (e) {
return anios[e.anioTtile] ? false : (anios[e.anioTtile] = true);
});
But the result is:
var data = [
{anioTtile: "2018", anioData:[10000,0,20000,0,0,0,0,0,0,0,0,0]},
{anioTtile: "2017", anioData:[10000,0,0,0,0,0,0,0,0,0,0,0]}
]
What I want is to have only the years without repeating and to have the most complete information, referring to anioData
, that is; the last array of each year, or if possible, allow me to unify the ones that are repeated
Example:
var data = [
{anioTtile: "2018", anioData:[10000,0,20000,0,50000,0,5000,5000,0,0,0,0]},
{anioTtile: "2017", anioData:[10000,0,20000,0,50000,0,5000,5000,0,0,0,0]}
]