最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - TypeError: Cannot read property 'push' of undefined-IONIC2 - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 4

try 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[] = [];
发布评论

评论列表(0)

  1. 暂无评论