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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:35:17+00:00 2026-06-08T18:35:17+00:00

How to convert following multidimensional array to single dimensional associative array with minimum loop

  • 0

How to convert following multidimensional array to single dimensional associative array with minimum loop in jQuery?

array(array('a'=>3),array('b'=>2),array('c'=>4),array('d'=>3))

Expected result:

array('a'=>3,'b'=>2,'c'=>4,'d'=>3);
  • 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-08T18:35:18+00:00Added an answer on June 8, 2026 at 6:35 pm
    {'a':3, 'b':2, 'c':4, 'd':3}
    

    …is the JS syntax you’re looking for in your result. JS doesn’t have associative arrays in the sense that, say, PHP does: it has objects, which do (approximately) the same job.

    If the code you show is valid in some other language (PHP?), it could be converted to a JSON string and when the JSON is parsed by JS you’d end up with a JS array of objects as follows:

    [ {'a':3}, {'b':2}, {'c':4}, {'d':3} ]
    

    To convert that to a JS object rather than an array of objects the simplest way is probably to make use of jQuery.extend():

    // assume some JSON.parse() or other process has created
    myArr = [ {'a':3}, {'b':2}, {'c':4}, {'d':3} ]
    // then
    
    var tmpArr = myArr.slice(0);   // make shallow copy of myArr
    tmpArr.unshift({});            // insert an empty object
    
    var newObj = jQuery.extend.apply(this, tmpArr);
    

    Demo: http://jsfiddle.net/SqcEw/

    Note that if more than one of the elements in the original array had the same property name one would clobber the other in the final object.

    Further reading:

    • Working with objects (page has some load errors at the moment, but normally this is a good reference and I’m sure MDN will fix it soon)
    • $.extend()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert following table data into nested array using PHP. I
How can I convert the following array: (Assume I don't know how many depth
I want to convert following Jquery code to use $.ajax intead of $.getJSON, what
How would you convert following code to use only jquery library? <html> <head> <script>
How would I convert the following to a VB.NET predicate using Array.Find? Private Function
How can you convert the following while loop to a for -loop in PHP?
How do I convert the following javascript to using JQuery? document.getElementById(asc).removeAttribute(href); document.getElementById(asc).onclick = ;
I have the following multidimensional array: $userList = array( 0 => array('id' => 1000,
I want to convert following html code into continuous string using jquery/javascript. <ul> <li>one</li>
How can I convert the following nested array into xml file? What will the

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.