-2

Been looking around haven't find a solution.. Might be a really stupid question (probably) but haven't found a way to access to it.

I have the class Iphone:

export class Iphone{
    version: string;
    fixes = [
        {fixlcdprice:null},
        {fixspeakerprice:null}
    ];
}

then I have an array of Iphone with data

export const IPHONES:Iphone[]=[
{
    version:'Iphone 4',
        fixes:[
           {fixlcdprice:19},
           {fixspeakerprice:19}
       ]

},

   {


    version:'Iphone 4s',
        fixes: [
            {fixlcdprice:19},
            {fixspeakerprice:29}
        ]
}
]

trying to access the price of the fixes but I can't.

have tryed

Iphone.fixes[0]  <-- returns (object, object)

then tryed

Iphone.fixes[0[0]] <-- returns nothing..
Iphone.fixes.fixlcdprice <-- doesnt work
Alex
  • 75
  • 10

2 Answers2

3

Looks like you want

Iphone.fixes[0].fixlcdprice

Karl Reid
  • 2,147
  • 1
  • 10
  • 16
0
Iphone=[
{
    version:'Iphone 4',
        fixes:[
           {fixlcdprice:19},
           {fixspeakerprice:19}
       ]

},

   {


    version:'Iphone 4s',
        fixes: [
            {fixlcdprice:19},
            {fixspeakerprice:29}
        ]
}
]

Iphone[0].fixes[0] gives you the disired result

Rahul
  • 462
  • 1
  • 4
  • 16