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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:47:35+00:00 2026-06-12T17:47:35+00:00

I want to create a JSON array like this: var ddBasic = [ {

  • 0

I want to create a JSON array like this:

var ddBasic = [
    { text: "Facebook", value: 1, },
    { text: "Twitter", value: 2, },
    { text: "LinkedIn", value: 3, },
    { text: "Foursquare", value: 4, }
];

I’m using data from last.fm, so it would be something like this:

var tags = [
        { text: "rock", value: "rock", },
        { text: "pop", value: "pop", },
    ];

It needs to have a comma at the end so the ddslick dropdown function ignores the imageSrc and other things it can use for a dropdown, other it throws this error:

Uncaught TypeError: Cannot read property 'imageSrc' of undefined

To tie everything together, I have:

$('#tag').ddslick({
    data: tags,
    onSelected: function(selectedData) {}   
});

This is the function that gets the tags:

var tags = [];

var getTopTracks = function () {
    $.getJSON(
    settings.PHP_REQUEST_URL, {
        method: "tag.getTopTags",
        api_key: settings.LASTFM_APIKEY,
        format: "json",
    },

    function (data) {
        var limit = 50;

        data.toptags.tag.sort(function (t1, t2) {
            return t2.count - t1.count;
        });

        $.each(data.toptags.tag, function (i, item) {
            if (i > limit) return false;
            console.log(item.name);
            tags.push({
                text: item.name,
                value: item.name
            });
        });
    });
};

// event handlers (load quando o form é invocado só)
getTopTracks();
alert(tags.length);

// define tema para a combobox   
$('#tag').ddslick({
    data: tags,
    onSelected: function (selectedData) {}
});

How can I accomplish this?

  • 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-12T17:47:36+00:00Added an answer on June 12, 2026 at 5:47 pm
    var tags = []; //initialised tags with length 0
    getTopTracks(); //fetching date in background (!)
    alert(tags.length); //running while data is still fitched (unless you've a 0ping connection => alerting length 0
    

    At the point you use the alert it’s very likely tags is not filled as $.getJSON() is an asynchronus request, meaning the request will be handled in the background and execution of the script continues. You have to use the callback method as you already did for filling up the array.

    This, getJSON, is a shorthand Ajax function, which is equivalent to:
    $.ajax({   
       url: url,
       dataType: 'json',
       data: data,
       success: callback
    });
    

    http://api.jquery.com/jQuery.getJSON/

    //getJSON success callback:
    function (data) {
        var limit = 50;
    
        data.toptags.tag.sort(function (t1, t2) {
            return t2.count - t1.count;
        });
    
        $.each(data.toptags.tag, function (i, item) {
            if (i > limit) return false;
            console.log(item.name);
            tags.push({
                text: item.name,
                value: item.name
            });
        });
        //alert the length AFTER the tags been pushed
        alert(tags.length);
    
        // define tema para a combobox   
        $('#tag').ddslick({
            data: tags,
            onSelected: function (selectedData) {}
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I want to create a JSON array. I have tried using: JSONArray jArray
This the model that I want to create using json file Ext.define('Users', { extend:
I have a json record like blow [{low:null,high:10,type:2,value:0},{low:10,high:60,type:1,value:10},{low:60,high:null,type:2,value:11}] I would like to create array
Possible Duplicate: PHP : Create array for JSON I have an array like this
I want to create JSON object using tow query in PHP , Then retrieve
I want to create a .NET webservice using C# with JSON. but I've error
I want to create a dictionary containing array and send it to GAE using
[I have some code to create a JSON array. In this code I am
I have a JSON array like this [{Email:someone@some.com,Name:ACO,Groups:[MOD_SW,MOD_PI,MOD_GE],Id:63,Url:aco}, {Email:someone@some.com,Name:Agpo,Groups:[MOD_PI],Id:22,Url:agpo}, {Email:someone@some.com,Name:Akatherm,Groups:[MOD_SW],Id:64,Url:akatherm}, {Email:someone@some.com,Name:Albrand,Groups:[MOD_PI,MOD_GE],Id:23,Url:albrand}] I want to
i want create a custom json data from the mssql 2008 results so that

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.