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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:24:33+00:00 2026-05-31T14:24:33+00:00

I have an array of Objects known as players, which is sorted often (so

  • 0

I have an array of Objects known as players, which is sorted often (so the index of a certain player will change every round). After two players finish a game, I want to update their objects with new scores. The only way I can think to do this (I’m new to Javascript) is the O(n) algorithm:

function updatePlayer(player){
    for(var i=0;i<players.length;i++)
    {
        if(players[i].name === player.name)
            players[i] = player;
    }
}

I know arrays have O(1) access times, is there some function I can use to reduce the order of this (Perhaps even eliminate the need for this function altogether)?

Useful info:

  • I’m fairly new to Javascript, so the better answer is one that explains more/I learn the most from.
  • I haven’t played with jQuery yet, so a solution that avoids that is preferable. If there’s no way to do this without jQuery, guess I’ll have to learn it.
  • 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-31T14:24:34+00:00Added an answer on May 31, 2026 at 2:24 pm

    Unless it’s really a problem, I would leave it as it is. This sounds like premature optimization really.

    How many players are there? And do you know this loop is slowing your application down? A for loop is quite common and this one certainly isn’t computationally intensive.

    You could indeed use a separate data structure for bookkeeping and fast access but you should only do that when it’s really needed. The reason is that it takes effort to keep the data structures in sync, things may get buggy, et cetera.

    • 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 in a known format, it could look like
I have an array of objects which populate a UITableView . When a user
I'm building an application which will have dynamic allocated objects of type A each
I have an array of objects and I need them sorted by their title
I have an array list containing objects from the class EventOnMap . Every object
In C++ I have an array of pointers to Player objects and want to
I have an array of objects which contains various kinds of data in it,
I have an unsorted array of objects. I need to know how I can
I have an Array of Objects that need the duplicates removed/filtered. I was going
I have an array of objects that have QTTime structs as attributes. The objects

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.