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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:07:01+00:00 2026-06-09T21:07:01+00:00

I have an array of several entries with some of them with same name

  • 0

I have an array of several entries with some of them with same name .All entries have location but one is empty.I want to save the same value of location into all entries of the array for same user. How can I do that?

      array=[{
                    user: angelos,
                    user_id: 121212,
                    date: 12/12/12,
                    profile_img: cfdf,
                    text: nhkjhgjtdkghd,
                    url: g.htm,
                    location:Romania
                },{
                    user: angelos,
                    user_id: 121212,
                    date: 12/12/12,
                    profile_img: cfdf,
                    text: nhkjhgjsdfsadstdkghd,
                    url: g.htm,
                    location:""
                },{
                    user: Mike,
                    user_id: 121212,
                    date: 12/12/12,
                    profile_img: cfdf,
                    text: nhkjhgjtdkghd,
                    url: g.htm,
                    location:New York
                },{
                    user: Mike,
                    user_id: 121212,
                    date: 12/12/12,
                    profile_img: cfdf,
                    text: nhkjhgjsdfsadstdkghd,
                    url: g.htm,
                    location:""
                }];
  • 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-09T21:07:02+00:00Added an answer on June 9, 2026 at 9:07 pm

    First, for each user, store its non-empty location. Then, in the second pass, simply set empty locations based on the stored user -> location map.

    var userLocationMap = {};
    for (var i = 0; i < array.length; i++) {
      if (array[i].location) {
        userLocationMap[array[i].user] = array[i].location;
      }
    }
    
    for (var i = 0; i < array.length; i++) {
      if (!array[i].location) {
        array[i].location = userLocationMap[array[i].user];
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array with several items inside and one of them is location
I have got an array with several twitter tweets and want to delete all
I have an object whose value may be one of several array types like
I have a mutable array that is retained and storing several objects. At some
I have a single array with several of the same values. And I only
I have an array of hex color codes and want to loop through them
I would like to save several records for one model. This would have been
I have a PHP array which has several different fields. For some of the
I have an array with some objects, and there are several objects that are
I have an array: this.entries = [] . I run some code and it

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.