Solved ! [this.x.push is not a function]

Commons-error-in-LWC-JavaScript.
Commons-error-in-LWC-JavaScript.

This type of error occur when you try to push data in array and you have not declare that variable as [] type .

Example :

image = ' ';

this.image.push({label:'testImage'});

The above code may give you following error .

The simplest way to solve this error is declare your with proper data type.

image = [];

this.image.push({label:'testImage'});

If you have found some another solution for the given issue then please post in comment section that may help other coders to save their time.

Leave a Reply