Skip to content

If is posible add function to conver all object to array? #4

Description

@root9

I got a lot [object Object],[object Object],[object Object],[object Object] in log on server.

I try some thing to use JSON.stringify but I have Circular reference problem so I write some code like this, maybe you can add to this addon if you like :)

This code maybe need to rewite to work better

varproducts=[{id:102,price:200.3},{id:3,price:104.5},{id:10,price:20},[{id:102,price:200.3},{id:3,price:104.5},{id:10,price:20},[{id:102,price:200.3},{id:3,price:104.5},{id:10,price:20},]]];functionconvert2array(obj,properties,deep,maxdeep){++deep;for(varkeyinobj){if(obj.hasOwnProperty(key)&&typeofobj[key]!=='function'){if(deep<maxdeep){if(obj[key]!=null&&typeofobj[key]==="object"){if(obj[key].length>0){properties[key]=[];convert2array(obj[key],properties[key],deep,maxdeep);}}elseif(typeofobj[key]==="number"||typeofobj[key]==="string"||typeofobj[key]==="boolean"){properties.push(key+': '+obj[key]);}else{// console.log('error: ' + key, obj[key]);}}}}returnproperties;}varcache=[];varproperties=[];JSON.stringify(products,function(key,value){if(typeofvalue==='object'&&value!==null){if(cache.indexOf(value)!==-1){// Circular reference found, discard keyreturn;}if(typeofvalue==="object"&&value!=null){varres=convert2array(value,properties,-1,4);properties.push(key+': '+res);cache.push(value);}elseif(typeofvalue==="number"||typeofvalue==="string"){properties.push(key+': '+value);cache.push(value);}}returnvalue;});console.log(properties);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions