How to compare value in this array

Hi guys,

I have a data like this:

[code]var rand = Math.floor((Math.random()*100)+1),
numbers = ;

function randomNumber () {
for (var i = 0, j = numbers.length; i < j; i += 1) {
var x = numbers[i];

I want to compare something like this:

if ( x === this.very.numbers[i] ) { // it's okay, you can proceed }

How can I do it?

What you want to achieve is not all that clear from the code, and the numbers array will always be filled with the same random number.

Can you please explain in words what you want to achieve?

The question is not actually that simple. I just try to ask simple question.
It was for node.js. The situation is when a user log in and go to a particular page.
He is automatically connected to a server through websocket setting.
There is a button on that page if the user want to get information design to serve for him. When he hit the button, his information is sent to a server.

At the server, node.js recorded connection. When it receive data it processes it by sending request to other server programs. When it get returned data, it sends that data back to the requester. Simple process.

However, there is problems. I don’t know how to send data back to that particular person. The code below just send data to everybody who is on the page:

var server = new WebSocketServer({port:8080}),
clients = ;

server.on('connection', function(ws) {

    ws.on('message', function(message, flags) {
        // 1. server receive requested data
        // 2. check database and user identity
        // 3. if okay read file and return data accordingly
        // 4. send data to the requester with a method below
        for (var i = 0, j = clients.length; i < j; i += 1) {

So how to compare something like this:

if ( clients[i] === this.very.requester ) { // send data to this person only }
Thank you,

It is the person that made the request, to who the response it send back to. It works in the same way that a web page is sent only to the person who requests it.

Other than the data that’s sent back to the requester, is there some reason why you would want to keep an open connection back to the requester?

Thank you for reply.

After helped people solved problem in another forum I realize that I could do it on a user machine. But it can be great if I can do it on a server as well.

Supposed it was a poker game, financial trading data, the user might want to always stay connected. Cut off connection is not a good idea. I notice that Chrome Beta for Android still received data in a sleep mode.

It seems then that you may be after a keep alive agent, that can help to keep the connection open for you.

Be careful of such things though. Connections are something that developers need to be frugal with, lest you lose the ability for others to connect to your server.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.