# Ionic array \[string, Array\<Consumption\>\] - key, value

**URL:** <https://forum.ionicframework.com/t/ionic-array-string-array-consumption-key-value/117771>\
**Category:** ionic-v3\
**Created:** [January 10, 2018, 4:32am UTC](https://forum.ionicframework.com/t/ionic-array-string-array-consumption-key-value/117771 "2018-01-10T04:32:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![piraba](https://avatars.discourse-cdn.com/v4/letter/p/a587f6/32.png) [@piraba](https://forum.ionicframework.com/u/piraba)\
**Post date:** [January 10, 2018, 4:32am UTC](https://forum.ionicframework.com/t/ionic-array-string-array-consumption-key-value/117771/1 "2018-01-10T04:32:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:55pm UTC](https://forum.ionicframework.com/t/ionic-array-string-array-consumption-key-value/117771/2 "2021-07-19T21:55:56Z")

</div>

Closed on July 19, 2021, 9:55pm UTC


