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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:41:17+00:00 2026-05-30T04:41:17+00:00

If I create a JavaScript object like: var lst = []; var row =

  • 0

If I create a JavaScript object like:

var lst = [];
var row = [];
row.Col1 = 'val1';
row.Col2 = 'val2'; 
lst.push(row);

And then convert it to a string:

JSON.stringify(lst);

The result is an object containing an empty object:

[[]]

I would expect it to serialize like:

[[Col1 : 'val1', Col2: 'val2']]

Why do the inner objects properties not serialize?

Code snippet at JSFiddle.

  • 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-30T04:41:19+00:00Added an answer on May 30, 2026 at 4:41 am

    Because row is an array, not an object. Change it to:

    var row = {};  
    

    This creates an object literal. Your code will then result in an array of objects (containing a single object):

    [{"Col1":"val1","Col2":"val2"}]
    

    Update

    To see what really happens, you can look at json2.js on GitHub. This is a (heavily reduced) snippet from the str function (called by JSON.stringify):

    if (Object.prototype.toString.apply(value) === '[object Array]') {
        //...
        length = value.length;
        for (i = 0; i < length; i += 1) {
            partial[i] = str(i, value) || 'null';
        }
        //...
    }
    //...
    for (k in value) {
        if (Object.prototype.hasOwnProperty.call(value, k)) {
            //...
        }
        //...
    }
    //...
    

    Notice that arrays are iterated over with a normal for loop, which only enumerates the array elements. Objects are iterated with a for...in loop, with a hasOwnProperty test to make sure the proeprty actually belongs to this object.

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

Sidebar

Related Questions

In javascript you can create a Date object from a string, like var mydate
I would like to create a valid JavaScript Date object from the following string
In javascript you can easily create objects and Arrays like so: var aObject =
I'd like to be able to create a javascript object from my html form
There are two different ways to create an empty object in JavaScript: var objectA
I like that in javascript, I can create a function, and then add further
Trying to create an object in Javascript (for Appcelerator/Titanium). The object is defined like
I am trying to create a JavaScript object as follows. var MyObject = function
As it is now I create a JavaScript object and then stringify it, put
V8's documentation explains how to create a Javascript object that wraps a C++ object

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.