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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:49:11+00:00 2026-06-17T13:49:11+00:00

Lets say I have a schema like this: users: { friends: [{name: String, id:

  • 0

Lets say I have a schema like this:

users: {
   friends: [{name: String, id: String}]
}

what is the fastest way to extract this object array into two separate arrays:

var names = [String]
var ids = [String]

Is there a way to do this without a for loop? This operation needs to be done for a set of users and im trying to avoid nested for loops. Maybe there is a better way to store the friends names and ids?

  • 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-17T13:49:12+00:00Added an answer on June 17, 2026 at 1:49 pm

    There’s always a loop, somewhere (and I’m not sure what you mean by nested loops?). 🙂

    If you’re looking for fastest (which is what you had said), using a map or a forEach isn’t generally speaking going to result in faster operation as each iteration is calling a function, which adds overhead.

    As you’ll see in this jsPerf, it’s generally better to use a for-loop construct. First, if the array is long, you’ll benefit from only going through the array just once (rather than once for each property). For futher optimization, predeclaring the array size also can improve performance.

    var names = new Array(totalFriends),
        ids = new Array(totalFriends), friend;
    
    for (var j = 0; j < totalFriends; j++) {
      friend = friends[j];
      names[j] = friend.name;
      ids[j] = friend.id;
    }
    

    A map call is convenient, but likely not the fastest.

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

Sidebar

Related Questions

Lets Say i have a table like this WEB_LIST_TABLE KEY Value ---------------------------------------- 134 google.com
Lets say I have a class A that is fairly simple like this -
Let's say we have an object model like this: public class Category { public
Lets say have this immutable record type: public class Record { public Record(int x,
Lets say I have multiple commands like 5000 which updates some column and row
This is pure curiosity. Let's say I have a resource Users and want to
I have a mongoose setup which involves an embedded-schema, lets say: A Blogpost with
Lets say I have a schema that defines the following XML: <Values> <Add Key=Key1>Value
I have a schema that looks like this: +----------+ | tour | +----------+ |
Let's say I have a table like this (ordered by id ): id amount

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.