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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:30:33+00:00 2026-05-19T02:30:33+00:00

This is almost exactly the same as this question json get key names as

  • 0

This is almost exactly the same as this question json get key names as text?, but that response isn’t working for me.

I’ve got a json object

{"userList":[
{"user1":[{"username":"mike","memberSince":"01/03/2011"}]},
{"user2":[{"username":"john","memberSince":"01/05/2011"}]},
]}

The only reason I have a the “user1” and “user2” labels is because I’m storing the userlist by userId in jQuery data, and then stringifying it to put it in a cookie and send it in another page. I know, sounds stupid, but I’m just building some front end stuff to prove a point before doing this properly with a db.

So the

jQuery('div#userList').data('user1',user1JSON);

turns into

{"user1":[{"username":"mike","memberSince":"01/03/2011"}]}

when using

var userlist=JSON.stringify(jQuery('div#userList').data());

Because of this, the user info is now a child of the userId, instead of just being a child of userlist.

In order to get the user info, I should be able to say

for(u=0;u<userList.length;u++){
   var userInfo=userList[u][0];
}

but unfortunately this is just giving me an undefined error. If I use

var userInfo = userList[u]['user1'];

I get the user info correctly.

So, can somebody correct me as to why userList[u][0] does not work, OR

explain to me how to use JSON.stringify without adding the userid to the beginning of the string?

  • 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-19T02:30:33+00:00Added an answer on May 19, 2026 at 2:30 am

    That is because the userList[u] returns an object, not an array.

    And you cannot access the object properties with an index..

    you could try

    for(u=0;u<userList.length;u++){
       for (var user in userList[u])
            {
              // user is the key
              // userList[u][user] is the value
              var userInfo=userList[u][user];
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question is almost exactly the same as this post , except that I'm
I'm almost certain I know the answer to this question, but I'm hoping there's
This is something that comes up so often I almost stopped thinking about it
When I asked this question I got almost always a definite yes you should
Note: Originally this question was asked for PostgreSQL, however, the answer applies to almost
Almost 5 years ago Joel Spolsky wrote this article, The Absolute Minimum Every Software
I know almost nothing about linq. I'm doing this: var apps = from app
I'm almost finished with the book Head First Java. The reason I'm studying this
Duplicate post, see: When do you use the "this" keyword? On almost every project
This is a bit of a long shot, but if anyone can figure it

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.