Friday, 24 August 2018

How to Create Dynamic associative array in typescript?

Hello



public data:Array<any> = [
{"id":10, "text": "First"},
{"id":11, "text": "Second"},
{"id":12, "text": "Third"},
{"id":10, "text": "Fourth"},
{"id":11, "text": "Fifth"},
{"id":13, "text": "Sixth"}
];
public array: any[][] = [];

for(let i: number=0;i<this.data.length;i++){
this.array[this.data[i].id] = this.array[this.data[i].id] || [];
this.array[this.data[i].id].push(this.data[i].text);
}

this.array.forEach(element => {
console.log(element);
});

4 comments:


  1. Good day. I was impressed with your article. Keep it up . You can also visit my site if you have time. Thank you and Bless you always.
    Outsource Angularjs Application Development in India

    ReplyDelete
  2. I really enjoyed reading this post. Thanks for sharing such useful insights.workday hcm course

    ReplyDelete
  3. A MuleSoft developer course online offers convenient learning for professionals who want to build API and integration development skills remotely. This MuleSoft developer course online covers Anypoint Platform, Mule flows, API design, DataWeave, connectors, testing, debugging, and deployment. Students develop practical expertise through hands-on assignments.

    ReplyDelete