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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:49:59+00:00 2026-06-02T15:49:59+00:00

is there a faster way to transform this: [ { name: ‘name1’, value: ‘value1’

  • 0

is there a faster way to transform this:

[
    { name: 'name1', value: 'value1' },
    { name: 'name2', value: 'value2' },
    { name: 'name3', value: 'value3' },
    ...
]

into this:

{
    name1: value1,
    name2: value2,
    name3: value3,
    ...
}

without manually looping and filling an object?
could the underscore library have a way to do this? it is already in our application, so
it can be used without an extra cost.

currently i have a manual action,
though i’m not sure it is the best performance i can have.

    var data = [];      // see the array above
    var result = {};
    for(var i = 0; i < data.length; i++)
    {
        var o = data[i];
        result[o.name] = o.value;
    }
  • 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-02T15:50:01+00:00Added an answer on June 2, 2026 at 3:50 pm

    I don’t think there is a faster way. With underscore there is a shorter way, but it’s almost certainly slower than your loop:

    var result = _.reduce(data, function(r,o) { r[o.name] = o.value; return r; }, {}); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a faster way to do this in python? [f for f in
This is a longshot, but is there a faster way to get size, lastaccessedtime,
In java is there a faster way of doing this? if (keyCode != 66
I'm curious if there is a slightly faster way to achieve this. Say for
Is there a faster way to do this? I guess this is unnecessary slow
Is there any way to optimize this piece of code to work faster? I'd
I currently use: BufferedReader input = new BufferedReader(new FileReader(filename)); Is there a faster way?
I wondering if there is a faster (GPU time) way to draw a full-screen
Is there any way to replace titles faster then str_replace function? I've got a
Is there a way to stream video with opencv faster? i'm using Mat img;

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.