var arrNewMarket=[];
var arrMarket=[
{id:1,country:"India",city:"city1",fruit:"Red Apple",year:2019,jan:220,feb:300},
{id:2,country:"India",city:"city1",fruit:"Green Apple",year:2019,jan:777,feb:555},
{id:3,country:"India",city:"city2",fruit:"Red Apple",year:2019,jan:333,feb:888},
]
console.log(arrMarket);
for (let i = 0; i < arrMarket.length-1; i++) {
for (let j = i+1; j < arrMarket.length; j++)
{
if(arrMarket[i].country==arrMarket[j].country && arrMarket[i].city==arrMarket[j].city) {
arrNewMarket.push({
id:4,
country:arrMarket[i].country,
city:arrMarket[i].city,
fruit:"Apple",
year:arrMarket[i].year,
jan:arrMarket[i].jan/arrMarket[j].jan,
feb:arrMarket[i].feb/arrMarket[j].feb,
});
}
}
}
我有一个包含多个对象的数组。
var arrMarket=[];
[
{id:1,country:India,city:city1,year:2019,jan:220,feb:300},
{id:2,country:India,city:city1,year:2019,jan:777,feb:555},
]
我们可以根据条件创建新对象,例如:如果国家匹配且城市匹配,那么一月和二月的一些“划分”计算,我们可以有第三个对象吗?
任何建议和帮助将不胜感激。
[
{id:1,country:India,city:city1,year:2019,jan:220,feb:300},
{id:2,country:India,city:city1,year:2019,jan:777,feb:555},
{id:3,country:India,city:city1,year:2019,jan:0.28,feb:0.54},
]
收到一只叮咚
相关分类