locked
Error with push in json object

    General discussion

  • Hey i am using json to store my data in js app

    but problem is that when i am using javaScript push method to add json object then it's working successfully but some extra null element also adding with it.

    <script>

    jsonArray=

    {

    "element1":[{"first":"raj"}]

    }

    var item={};

    item["first"]="deepak";

    jsonArray.element1.push(item);

    </script>

    Result:

    jsonArray={"element1":[{"first":"raj"},{"first":"deepak"},{},{}]}


    Deepak

    Friday, February 6, 2015 4:12 PM

All replies

  • Hi,

    I cannot reproduce. When I run the codes above, the jsonArray result is below:

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Monday, February 9, 2015 2:50 AM
  • hey anne i couldn't get you.

    actually i am saving this array into html localStorage by this code 
    localStorage.setItem("savedData", JSON.stringify(jsonArray));

    and its saving successfully but when i load it again when i get back to html page and parse that saved data then i found that there is some additional null elements have added.

    i am tired of this.

    thanks for your support



    Deepak

    Friday, February 13, 2015 9:04 AM