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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:17:13+00:00 2026-06-18T12:17:13+00:00

I have an associative array here – var dataset = { person : [

  • 0

I have an associative array here –

var dataset = {
    "person" : [    
        {"userLabels": ["Name","Role"]},
        {"tagNames": ["lName","role"]},
        {"tableClass": "width530"},
        {"colWidths": ["50%","50%"]}
    ]
}

I tried accessing the ‘userLabels’ object using jQuery using various methods but I failed. I think I am doing something wrong with basics. I want the userLabels object to be accessed using jQuery and the result should be an array, so I can perform the jQuery.inArray() operation.

  • 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-18T12:17:14+00:00Added an answer on June 18, 2026 at 12:17 pm

    Firstly, here’s how you can access dataset using the method you have.

    var dataset = 
    {
      "person" : [  
              {"userLabels": ["Name","Role"]},
              {"tagNames": ["lName","role"]},
              {"tableClass": "width530"},
              {"colWidths": ["50%","50%"]}
             ]
    };
    
    
    
     alert(dataset['person'][0]['userLabels']);    //style 1
    
     alert(dataset.person[0]['userLabels']);    //style 2
    
     alert(dataset.person[0].userLabels);    //style 3
    
     //Also you can use variables in place of specifying the names as well i.e.
    
     var propName ='userLabels';
     alert(dataset.person[0][propName]);
    
     //What follows is how to search if a value is in the array 'userLabels'
     $.inArray('Name', dataset.person[0].userLabels);
    

    I’d like to ask why you’re doing this in a such an ‘interesting way’. Why don’t you just make them all objects?

    That’s what I would do if I were you because if you think about it, a person IS an object and it should be noted that arrays are basically objects in Javascript with a ‘length’ property, though I won’t elaborate on it here (feel free to do some research though). I’m guessing it’s because you don’t know how to iterate over object properties. Of course if it makes more sense to you, go for it.

    Note one of the differences between an array and an object is that object properties need to be defined; you’ll notice that I gave ‘Name’ and ‘Role’ values of ‘undefined’ below.

    In any case, here is what I would do:

    var dataset = 
    {
      "person" : {
              "userLabels": {"Name" : undefined,"Role": undefined},
              "tagNames": {"lName" : undefined,"role" : undefined},
              "tableClass": "width530",
              "colWidths": ["50%","50%"]
            }
    };
    
    for (var i in dataset) { //iterate over all the objects in dataset
       console.log(dataset[i]);   //I prefer to use console.log() to write but it's only in firefox
       alert(dataset[i]);    // works in IE.
    }
    
     //By using an object all you need to do is:
    
     dataset.person.userLabels.hasOwnProperty('Role'); //returns true or false
    

    Anyways, hope this helps.

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

Sidebar

Related Questions

I have an associative array which when var dumped looks like this: Array (
I have an associative array: var array1 = { a1: { id: box1, title:
I have a xml parser that returns an associative array. Here's the structure: <addresses
I have an associative array in awk that gets populated like this: chr_count[$3]++ When
I have an associative array that I want to display using TileList. However, it
I have an associative array assigned to a Smarty variable, something like this: $foo
i have an associative array in PHP. $myarray = array( a=>News, b=>Articles, c=>images );
So, I have an associative array and the keys in the array are properties
I have a simple associative array: $ar = array( 1=>'foo', 2=>'bar', 5=>'foobar', 8=>'barfoo' )
I have a nested associative array like this: $inputTypes= array( natural => array( text,

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.