Reputation: 65
I am using node-red, the function node to generate some random matrix. However, every time when I deploy the node, the error "TypeError: Cannot read property 'push' of undefined" will appear, can someone help me to take a look at the code?
// Generate some random data
// See https://www.patrick-wied.at/static/heatmapjs/example-minimal-config.html
var len = 200;
msg.payload = [];
while (len--) {
var value = Math.floor(Math.random() * 100);
msg.payload.push(value);
}
return msg;
Upvotes: 2
Views: 1668
Reputation: 55
The error tells , push cannot be done on 'undefined'. This suggests that msg is undefined or msg.payload is undefined. In your case, declare the payload separately before push and then assign it to the msg finally.
Upvotes: 4