Twitch Clips Twitch Clips - 27 days ago 6
Node.js Question

object.push is not a function [Node/Socket.io]

var object = {

}

socket.on('call', function(data){
console.log(data); // On console: { number: 68, name: 'John' }
object.push(data);
});


In the console.log I get the object just fine. But the push function doesn't seem to be working.

    object.push(data);
            ^
 
TypeError: object.push is not a function

Answer Source

object here is an Object, so not have the push function.

If you want to use an object use object[key] = value; or object.key = value;


Array.push in others hand exists.

var object = [];

object.push(value);