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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:09:02+00:00 2026-06-15T22:09:02+00:00

I hard coded the following array and I can use it to insert selections

  • 0

I hard coded the following array and I can use it to insert selections into an Autocomplete dropdown. It seems to be an array of JSON objects, though I am a JS novice and could be wrong. It works.

var boroughData = [
    {"label":"New York, Bronx, Bronx County, New York, United States","value":"Bronx, Bronx County, New York, United States"},
    {"label":"New York, Staten Island, Richmond County, New York, United States","value":"Staten Island, Richmond County, New York, United States"}
];

I want to provide similar data from a database and assemble it via a .map() function. I have something working, but the output is a different format/type. It seems to be an array with one long string, though again, I could be wrong. An example (with different cities) is below. Note the initial and ending ” that is not in my hard coded array above.

["{"label":"Dallas, Cockr... Texas, United States"}", "{"label":"Dallas, Downt... Texas, United States"}", "{"label":"Dallas, East ... Texas, United States"}"]

The data from the database currently looks like the following, though it could be changed, if that helps.

{"label":"Dallas, Cockrell Hill, Dallas County, Texas, United States", "value":"Dallas, Cockrell Hill, Dallas County, Texas, United States"}

I tried string manipulation to replace/remove the initial and ending ” but I could not get it to work. Maybe I need something different in the .map() function to create objects. My .map() in an ajax success option is as follows

success: function (data){
    boroughData = $.map( data, function (item){
        return item.boroughString;
        //returning {"label":"Dallas, Cockrell Hill, Dallas County, Texas, United States", "value":"Dallas, Cockrell Hill, Dallas County, Texas, United States"}
    });
    alert(jQuery.isArray(boroughData)  + "|bD1"); //true, is array
    return boroughData;
}

How do I get a return result that is the same type/format as my hard coded array? Please be specific with code. I don’t follow general instructions well.

  • 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-15T22:09:04+00:00Added an answer on June 15, 2026 at 10:09 pm

    Since the data that you get in item.boroughString is a string, you probably can parse it with JSON.parse (or use json2.js for browsers who don’t support this functionality – see also this question : Parse JSON in JavaScript?) and it should convert you this string in a full JSON object.

    $.ajax({
        success: function (data){
            boroughData = $.map( data, function (item){
                return JSON.parse(item.boroughString);
                // should return JSON object {"label":"Dallas, Cockrell Hill, Dallas County, Texas, United States", "value":"Dallas, Cockrell Hill, Dallas County, Texas, United States"}
            });
    
            alert(jQuery.isArray(boroughData)  + "|bD1"); //true, it is again an array
    
            //return boroughData; Your success should not return a variable to be used after!!! Ajax is asynchronous
            //
            // Rather use a callback function
            functionToBeExecutedAfterTheSuccess();
        }
    });
    
    function functionToBeExecutedAfterTheSuccess() {
        alert(boroughData + "|bD3"); //[object Object],[object Object],[object Object] with OK contents
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an javascript array that is hard coded into my javascript file: var
I'm following an example where the author hard coded a paddingTop to 370px. ...
I'm doing a graph with Quartz, following this tutorial . This is my hard-coded
I have hard-coded data into a .jsp file. What I want to do is
I'm having a hard time understanding why the following code doesn't work. I'm sure
Hi I am hitting std::out_of_range: basic_string::substr in the following code. Have been trying hard
I have currently hard-coded in some data for a demo of a project. The
I have a very hard-coded XML reader below: using System; using System.Collections.Generic; using System.Linq;
Right now I've hard coded the whole xml file in my python script and
I have a hard coded URL like so: https://bupacouk.bwa.local.internal.bupa.co.uk/cash-plan-quote/quoteAction.do?getBenefitLevelDetails=getBenefitLevelDetails&productPolicyId=7841#a1 When Javascript is enabled i

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.