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

  • SEARCH
  • Home
  • 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 7367817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:35:08+00:00 2026-05-29T03:35:08+00:00

I have 2 arrays of objects : users and channels. Each user can be

  • 0

I have 2 arrays of objects: users and channels. Each user can be in many channels. Each channel can contain many users.

Channel object example:

{name: "test", visible: true, active: true}

User object example:

{name: "user", ip: '127.0.0.1', sex: 1}

Script must do such actions:

  1. Display users list by channel.
  2. Display channels list by user.
  3. All basic actions (add/remove/update user/channel);

What will be the better way to implement linking between these objects:

  1. User will contain his channels list.
  2. Channel will contain his users list.
  3. Create separate object which will contain user=channel assosiations.
  4. Or your variant…

I think that third variant will be better.

  • 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-05-29T03:35:08+00:00Added an answer on May 29, 2026 at 3:35 am

    As you are aware, there are many ways to do this and which way ultimately depends more on how you’re going to use, access and store the data than you have disclosed to us. But, here’s one way that could work:

    Create an object for a user:

    function user(name, id, ip, sex, channels) {
        this.name = name;
        this.id = id;
        this.channels = channels || [];
        this.ip = ip;
        this.sex = sex;
    
        this.addChannel = function(channel) {
            this.channels.push(channel);
        }
    }
    

    Then, you can have an array of user objects, where each user object contains the basic information about the user and contains the list of channels. This data structure choice optimized for being able to easily know which channels a user belongs to.

    This structure does not optimize for knowing which users are in a given channel. If you wanted that information from this data structure, you could still calculate it, but it would involve looking in every user object to find out which users were in a given channel. It’s doable, but not fast.

    If you need both types of information (which channels a user is in and which users are in a channel) available fast, then you may need to double maintain two data structures, one that gives you each answer. If you do all manipulation of the channels via methods or helper functions, then they can both be maintained automatically.

    The choice ultimately depends upon how you most need to access the data and which types of access must be fast. Since you haven’t shared that info, we can’t really say which would be better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of objects (Users) each user has an nsset named devices
I have an object that works with arrays of smaller objects. I am now
I have a collection of objects @users , each having its id attribute. @users
I have two arrays with different attributes for the objects contained in each. participants
Suppose I have an array of a objects of user defined class. Wanted to
I have an array of objects which populate a UITableView . When a user
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have an array of FileReference objects which have several listeners attached to each
I have a class that contains multiple user objects and as such has an
I have Javascript array which contains User object. I have created this array from

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.