Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8790639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:42:35+00:00 2026-06-13T22:42:35+00:00

I’m, by no means, JS fluent, so forgive me if im asking for some

  • 0

I’m, by no means, JS fluent, so forgive me if im asking for some really basic stuff, but I’ve not being able to find a proper answer to my question.

Im writting my first Node.js (plus Extra Framework and Socket.io) app and Im having some fun setting up the server side of a FB-like messenger (surprise!!!).

So, let’s say I have this data structure to store online users(This is a JSON Array, but I’m not sure it is the best way to do it or should I go with Javascript Objects):

[
  {
    "site": 45,
    "users": [
        {
            "idUser": 5,
            "idSocket": "qwe87r7w8qwe",
            "name": "Carlos Ray Norris"
        },
        {
            "idUser": 6,
            "idSocket": "v8d9d0fgfs7d",
            "name": "John Connor"
        }
    ]
},
{
    "site": 48,
    "users": [
          {
            "idUser": 22,
            "idSocket": "qwe87r7w8qwe",
            "name": "David Bowie"
          },
          {
            "idUser": 23,
            "idSocket": "v8d9d0fgfs7d",
            "name": "Barack H. Obama"
          }
      ]
  }
]

What I want to do is to search in the array for x value given y. In this case, retrieving the idSocket knowing the idUser WITHOUT having to run through the array values.

So I have basically 2 questions: first, what would be the proper way to store users online? and secondly, how to find values matching with the values I already know (find the idSocket that has a given idUser).

I would like a pure JS approach(or using some of the tools given by Node, Socket.io or Express), but if that’s not possible then I can look for some JQuery.

EDIT
I took chovy’s advice and modified a little the structure, now it looks like this

{
  45: { // site
    05: { // userId
        "name": "Carlos Ray Norris",
        "socketID": "qwe87r7w8qwe"
    },
    06: {
        "name": "John Connor",
        "socketID": "v8d9d0fgfs7d"
    }
},
48: {
    22: {
        "name": "David Bowie",
        "socketID": "erv7e6v876vr"
    },
    23: {
        "name": "Barack H. Obama",
        "socketID": "brt877brtt87"
    }
  }
}

Thanks to Node.js, I can easily access to the data like this (I know both, the site and userId value) var socket = data[site]["05"].socketId. Im guessing this is done thanks to Node.js, but Im not completely sure.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:42:36+00:00Added an answer on June 13, 2026 at 10:42 pm

    Can you structure your data so the user id is the key, instead of an array you have to loop over?

    var data = {
     45: { user: 'Fred' },
     58: { user: 'Sam' )
    };
    
    
    var userId = 45;
    data[userId].user // => 'Fred'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.