javascript - How can I return a new object based on a filter? -
javascript - How can I return a new object based on a filter? -
i have js:
var json = {"products":[{"id":"6066157707315577","reference_prefix":"bb","name":"beaniebaby","product_line":false,"has_ideas":true},{"id":"6066197229601550","reference_prefix":"bbags","name":"blackbags","product_line":false,"has_ideas":false}],"pagination":{"total_records":4,"total_pages":1,"current_page":1}} var stuff = json.products.filter(function(obj) { homecoming obj.has_ideas === true }); console.log(stuff);
i need help returning js obj in same format started in (var json = {"products":[...) containing filtered objects if exist. if not, want empty array. how do this?
just create object , fill in 'products' property :
var jsonobj = {"products":[{"id":"6066157707315577","reference_prefix":"bb","name":"beaniebaby","product_line":false,"has_ideas":true},{"id":"6066197229601550","reference_prefix":"bbags","name":"blackbags","product_line":false,"has_ideas":false}],"pagination":{"total_records":4,"total_pages":1,"current_page":1}} var stuff = {}; stuff.products = jsonobj.products.filter(function(obj) { homecoming obj.has_ideas === true }); console.log(stuff);
javascript arrays
Comments
Post a Comment