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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:07:08+00:00 2026-05-20T10:07:08+00:00

Given any object with members that look like this: target { x1 : 1

  • 0

Given any object with members that look like this:

target
{
    x1 : 1
    x2 : 2
    x3 : 3
    y1 : 6
    y2 : 5
    y3 : 4
}

I need to transform the object into something like this:

target
{
    x : [1, 2, 3]
    y : [6, 5, 4]
}

From the basic JavaScript I know, it seems like the following function would work:

function joinParameters(target, paramName) {
    var count = 1;
    var array = [];
    var name = paramName.concat(count);
    var value = target[name];
    while (typeof value != undefined) {
        array.push(value);
        name = paramName.concat(count);
    }
    target[paramName] = array;
}

So, I could say joinParameters(target, “x”); The problem, however, is that

    var value = target[name];

is always undefined. I followed the code in FireBug to make sure that the target object has the property that I’m trying to get, and it does. So, I’m not quite sure what’s wrong.

If jQuery has an elegant way of doing this, then I would prefer that solution.

  • 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-20T10:07:09+00:00Added an answer on May 20, 2026 at 10:07 am

    Using underscore.js:

    _(target).keys().reduce(function(memo, key){
        var split = /([^\d]+)([\d]+)/.exec(key);
        memo[split[1]] = memo[split[1]]||[];
        memo[split[1]][parseInt(split[2],10)-1] = target[key];
        return memo;
    },{});
    

    Working example:

    http://jsfiddle.net/PLgN5/

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

Sidebar

Related Questions

Do you generally assume that toString() on any given object has a low cost
Given a Python object of any kind, is there an easy way to get
Given any arbitrary, one-line string, my goal is to render it into a bitmap
Given a source color of any hue by the system or user, I'd like
In the context of C#, .Net 4... Given a data source object that supplies
Given the following declaration: <Extension()> Public Function ToJSON(ByVal target As Object) As String Dim
I want to replicate any given Javascript loop , class , function to into
Estimating how long any given task will take seems to be one of the
A QA server of mine which has not given me any flack for a
We have a JavaScript function named move which does just windows.location.href = any given

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.