javascript - how to create json object in angular js -


this.addtocart = function(id,name,category,price) {     alert(id+"name"+name);      var eachproduct = [         {             "name": name,             "id": id,             "category":category,             "price":price         }       ];     alert(eachproduct.name);//i getting undefine     addedproductslist.push(eachproduct);      sessionstorage.setitem("addedproductslist", addedproductslist);      return "success"; }; 

how pass function parameters each product?

as abdul has pointed out have json array , want json object, there need

  var eachproduct =                       {                          "name": name,                          "id": id,                          "category":category,                          "price":price                      }; 

now alert(eachproduct.name); return name. , assume "how pass function parameters each product" mean add attribute json object. you have

eachproduct["someattribute"]='"value":somevalue'; 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -