Javascript Push Product Info as Object to an Empty Array -
i have array of products add product information object empty array.
var data = { "vegetables": [ { "id": "1", "title": "peas", "type": "green", }, { "id": "2", "title": "carrots", "type": "root", } ], "protein": [ { "id": "3", "title": "steak", "type": "meat", }, { "id": "4", "title": "eggs", "type": "dairy" } ]}
i able push title empty result array following:
function getcategory() { result = []; (let item in data) { data[item].foreach(v => result.push(v.title)); } document.write(result); } getcategory();
but able push product information object can formatting. example:
var myobj= "" ; myobj = "<div class='box'>" + title +"<br> "+ type + "</div>"; result.push(myobj); // push result[]
i unsure how adapt body of loop accommodate object:
data[item].foreach(v => result.push(v.title + v.type)); // needs pushed object.
any appreciated.
cheers
Comments
Post a Comment