title: How to use the client ID in HTML5 websocket and node.js chat?
body: <p>I'm trying to send private message between users in a simple chat that I created using HTML5 websocket and node.js.</p>
  
  <p>When the users connect, I create a simple ID for them (connection ID) and add that to this <code>CLIENTS=[];</code></p>
  
  <p>When I do a <code>console.log(CLIENTS);</code>, I see all the IDs like this:</p>
  
  <pre><code>[0, 1, 2]
  </code></pre>
  
  <p>Now I need to use the IDs to send Private messages to the users.</p>
  
  <p>So i went ahead and this <em>(For the testing purposes, I just need to send the message to the user with ID 2)</em>:</p>
  
  <pre><code>var express = require('express'),
          app = express(),
          http = require('http').Server(app),
          WebSocketServer = require('ws').Server,
          wss = new WebSocketServer({
              port: 8080
          });
  
      CLIENTS = [];
      connectionIDCounter = 0;
  
  
      app.use(express.static('public'));
  
      app.get('/', function(req, res) {
          res.sendFile(__dirname + '/index.html');
      });
  
      wss.broadcast = function broadcast(data) {
          wss.clients.forEach(function each(client) {
              client.send(data);
          });
      };
  
      wss.on('connection', function(ws) {
  
      /////////SEE THE IDs HERE////////////////
  
      ws.id = connectionIDCounter++;
      CLIENTS.push(ws.id);
      console.log(CLIENTS);
  
  
          ws.on('message', function(msg) {
              data = JSON.parse(msg);
  
  
      /////SEND A PRIVATE MESSAGE TO USER WITH THE ID 2//////
  
      CLIENTS['2'].send(data.message);
  
      });
  
  });
  
  http.listen(3000, function() {
      console.log('listening on *:3000');
  });
  </code></pre>
  
  <p>When I run my code, I get the following error:</p>
  
  <pre><code>TypeError: CLIENTS.2.send is not a function
  </code></pre>
  
  <p>Could someone please advice on this issue?</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thanks in advance. </p>