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 7714295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:05:32+00:00 2026-06-01T02:05:32+00:00

Here’s a simplified example of an object I have. What I would like to

  • 0

Here’s a simplified example of an object I have. What I would like to do is when I’m calling the update method, for it to update based on all objects. So, I’ll need to keep track of all objects somehow (can I do this within this Game object? or do I need to wrap this?)

var Game = function() {
    this.data      = [];
}

Game.prototype = {

    add: function(game) {
        this.data.push(game);   
    },
    update: function(game) {
        for(i = 0; i < this.data.length; i++) {
            if(this.data[i].id == game.id) {
                this.data[i].name = game.name;
             }
         }
    },
    get: function() {
        console.log(this.data);
    }
}


var g1 = new Game;
g1.add({id: '5', name: 'firstname'});
g1.add({id: '6', name: 'secondname'});

var g2 = new Game;
g2.add({id: '5', name: 'firstname'});
g2.add({id: '6', name: 'secondname'});

g1.update({id: '5', name: 'firstname-updated'})

g1.get();
g2.get();

Basically, if you run this, you’ll see that g1.get() writes the data with the updated id 5, where as g2, will still have it’s original id 5 with name ‘firstname’.

Thanks a lot for any help!

EDIT: Just wanted to add, I would still want there to be multiple objects. It’s not always, that each object will have matching ids. But if they do, they should all update.

  • 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-01T02:05:34+00:00Added an answer on June 1, 2026 at 2:05 am

    You could do something like:

    function Game() {
      this.data = [];
    }
    
    // Object to store games with the same id
    Game.games = {};
    
    Game.prototype.add = function(game) {
    
      // Add the game to the existing array with same id
      if (Game.games[game.id]) {
        Game.games[game.id].push(game);
    
      // Or create new array if first with this id
      } else {
        Game.games[game.id] = [game];
      }
      // other stuff
    }
    
    // Update all games with same id
    Game.prototype.update = function(game) {
      var games = Game.games[game.id]
      // games is a reference to an array of all the games with the same id
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is an example: I have a file 1.js, which has some functions. I
Here is an example: I have the generic type called Account. I wish to
Here I have an int x=3; NSLog(@%i, x); How to have it displayed like
Here is an example of what I need http://code.google.com/webtoolkit/doc/latest/tutorial/gettingstarted.html I need interactive list to
Here is jsFiddle Is it possible, to make table react like select? I need
Here is my problem...I have a page that loads a list of clients and
Here is my situation: I am using telerik with winform. I have a dataset
Here's the basic setup: I have a thin bar at the top of a
Here is my problem : I have a post controller with the action create.
Here is an example. foreach (var doc in documents) { var processor = this.factory.Create();

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.