Issue
I used array.unshift() with my Angular2 project. And I got
TypeError: Cannot read property 'unshift' of undefined.
Typescript is a superset of JavaScript. Why array.unshift() is not recognized?
How can I add new item to the beginning of an array with Typescript?
Solution
That error is saying that whichever identifier you are trying to invoke unshift() on actually has the value 'undefined' instead of array.
It's like if you were doing this:
var array = undefined;
array.unshift();
when you actually want this:
var array = [];
array.unshift();
double check that you are initializing your array correctly.
Answered By - awiseman
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.