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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:03:47+00:00 2026-06-05T06:03:47+00:00

I have a returned object list: data.d[15] and one sample of it: data.d[3] =

  • 0

I have a returned object list: data.d[15]

and one sample of it:

data.d[3] = {
CityId: 2,
CityName: "Ankara"}

I want to convert it to one object as

cities{
1: "Istanbul",
2: "Ankara",
3: "New York"
}

And it should be generic, so I dont know the “CityId” and “CityName” field names.
what is the best method for it?

thank you all… i have send fieldnames by field object -no dependencies important for this code-, it has been resolved.

            var url = this.options.url + "/" + field.values,
                id = field.fieldId,
                title = field.fieldTitle;

            this.getJSON(url, {}, function (rData) {
                var obj = {};

                for (i = 0; i < rData.d.length; i++)
                    obj[rData.d[i][id]] = rData.d[i][title];

                $("#" + parentId).html(self.getHtmlOfFormData(type, obj));
            });
  • 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-05T06:03:48+00:00Added an answer on June 5, 2026 at 6:03 am

    Maybe you need to detect which property contains the name of the city. Maybe something like this can work?

    var idprop, nameprop;
    for (var prop in data.d[0]) {
        if (typeof data.d[0][prop] === "string") nameprop = prop;
        if (typeof data.d[0][prop] === "number") idprop = prop;
    }
    
    var cities = {};
    for (var i = 0; i < data.d.length; i++)
       cities[data.d[i][idprop]] = data.d[i][nameprop];
    

    Keep in mind that this works if:

    1. data.d isn’t an empty array;
    2. there’s just one string property that contains the city name;
    3. there’s just one numeric property that contains the city id.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML object being returned, and inside is a date and time
I have a JSON Object that is returned from a web service call that
I have an android.net.URI object (of the kind returned by onActivityResult after MediaStore.ACTION_VIDEO_CAPTURE): it
I have a ResultSet object containing all the rows returned from an sql query.
I have a void pointer returned by dlsym(), I want to call the function
I have a string being returned from my database that I want to use
I've got a pretty complex object graph that I want to load in one
refers to : Reflection - setting Type of returned obj? I have a object
Wondering the best way to populate a GridView with my object data. I have
I have 2 JS files, one containing a list of generic functions to be

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.