You need to sign in to do that
Don't have an account?
Sumesh Chandran
@track array variable cannot read property push of undefined
I have a track variable which is declared as an array. When I push data to it, I get the error "Cannot read property 'push' of undefined". Also the console.log below get the correct length.
@track cities = []; markerClick(e) { let province = ''; getCitiesByProvince({ province: province, }).then(result => { console.log(result.length) for (let i = 0; i < result.length; i++) { this.cities.push(result[i]); } }); }
Post your apex class here. Your JS code looks fine.
May be i think the problem was in result data returned from class is it list or any thing else ? . Because your js trying to access the value from result and then it pushed to array.
Thanks,
Maharajan.C
Please see the code below, I am invoking the markerClick event when the user clicks on the marker inside a map. Could that be a reaon for this error message.
Please advise!
Sfdcfox helped out on Stackechange. Silly that I didn't put my whole code right at the beginning.
https://salesforce.stackexchange.com/questions/301692/pushing-to-track-array-variable-says-cannot-read-property-push-of-undefined