My requirement is array key, value pair.
consData: [string, Array];
premiseData: Array;
getConsumptionData(customerId : string, consList : Array<Consumption>){
for (var i = 0; i < consList.length; i++) {
if (consList[i].MSSL != ""){
if (condition : checking key exist ){
//take key's value and add object to array.
this.premiseData = this.consData[consList[i].MSSL]
this.premiseData.push(consList[i]);
} else {
//add new key and value
this.consData[consList[i].MSSL] = consList[i];
}
}
return consList[i].startDate;
}
}
the key is “msl” , if the key exists in the array, add this values to value’s array. If not add new key and value-add into values’ array.
Sampe JSON output.
{
"status": "success",
"Consumption" : [
{
"customerId" : "1",
"invNo" : "aaa",
"invDate" : "2018/1/21 06:10",
"msl" : "MSL1",
"eb" : "EB1",
"startDate" : "2017/06/01 06:10",
"endDate" : "2017/07/30 06:10",
"usage : 5000.00
},
{
"customerId" : "1",
"invNo" : "aaa",
"invDate" : "2018/1/21 06:10",
"msl" : "MSL2",
"eb" : "EB21",
"startDate" : "2017/07/01 06:10",
"endDate" : "2017/07/31 06:10",
"usage" : 5000.00
}
]
}
please advice me, how can i get the separate arrays for respective MSL number.
I am new to ionic.