jeudi 4 février 2016

JSON.parse returning [Object object] Looking to access properties of object

So I am trying to do some front end unit testing for my web app. In the view where the user can add a product, I have the following code:

 var ProductEntry = {Title: ProductTitle, Description: Description, Hashtags: Hashtags,
            Picture1: Picture1, Picture2: Picture2, Picture3: Picture3, Start: startdate, ETA: 
            ETADate}

        ProductsArray.push(ProductEntry);

        localStorage.setItem("Product", JSON.stringify(ProductsArray));

In the view where I am trying to retrieve the Array my jQuery code is:

 $("#SearchButton").click(function(){
        var SearchQuery = document.getElementById("SearchField").value; 
        var storageObject = JSON.parse(localStorage.getItem("Product"));
        alert(storageObject[1].Title);           
    });

Above, I am trying to access the property 'Title' of the ProductEntry object. Where am I going wrong? Switching over from C# MVC environment for this project.




Aucun commentaire:

Enregistrer un commentaire