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
Post a Comment