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

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -