How to get Socket.Io message length (nb of char)

I must get the socket io message length (of the variable)

I try this code but it doesn't work.

socket.on('message', function (message) {
   var messagelength = message.length; // This variable must contain the number of chars in the string.
});

This error can't be behind because I can show this variable correctly.

Sorry for my bad english.

I'd say that your message is an object or another type that has no length parameter.

try :

socket.on('message', function (message) {
   var messagelength = message.toString().length; // or if message is JSON, use JSON.stringify(message).length
});