Ola Zeyad
Ola Zeyad

Reputation: 113

how to create json object in angular2

i want to create J SON object in angular2 like this:

{ "classifications": [ 
                      { "type1" : [{"name":"text"},{"name":"text2"},{"name":"text2"}]} , 
                      { "type2" : [{"name":"image"},{"name":"img2"},{"name":"img3"},{"name":"img4"}]} ,
                      { "type3" : [{"name":"mp3"}]}
                      ] 
        }

is this the right way or not?? if not then how to make it and how to get data from this J SON object??

Upvotes: 1

Views: 23637

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657466

let x = { "classifications": [ 
                      { "type1" : [{"name":"text"},{"name":"text2"},{"name":"text2"}]} , 
                      { "type2" : [{"name":"image"},{"name":"img2"},{"name":"img3"},{"name":"img4"}]} ,
                      { "type3" : [{"name":"mp3"}]}
                      ] 
        }

console.log(x.classifications[0].type1[0].name);

Upvotes: 2

Related Questions