I'm trying to push
iterated value to array
json_resp
is Json response.
my Typescript code
export class hello {
CategoryLst:any[];
var catIndex,BillerIndex;
for(catIndex = 0; catIndex <= json_resp.category.length; catIndex++) {
var Clst = json_resp.category[0].categoryName;
this.CategoryLst.push(Clst);
}
}
while trying to execute its throwing error as
ORIGINAL EXCEPTION: TypeError: Cannot read property 'push' of undefined
is there something am i missing ??
I'm trying to push
iterated value to array
json_resp
is Json response.
my Typescript code
export class hello {
CategoryLst:any[];
var catIndex,BillerIndex;
for(catIndex = 0; catIndex <= json_resp.category.length; catIndex++) {
var Clst = json_resp.category[0].categoryName;
this.CategoryLst.push(Clst);
}
}
while trying to execute its throwing error as
ORIGINAL EXCEPTION: TypeError: Cannot read property 'push' of undefined
is there something am i missing ??
Share Improve this question edited Jan 8, 2019 at 4:08 pizzaisdavid 4693 silver badges14 bronze badges asked Jun 22, 2016 at 10:23 KartiikeyaKartiikeya 2,5269 gold badges39 silver badges70 bronze badges2 Answers
Reset to default 4try this
CategoryLst:any[] = [];
CategoryLst:any[]
is just specifying the type of the array
, but not assigning it, so by default the value of that array would be undefined
.
In order to initialize it in the same declaration, you should do it this way:
CategoryLst:any[] = [];