@bharathpanchak Thank you for poiniting out my mistake. I tried one solution
function getPurgedObj(obj){ let stringfiedObj = JSON.stringify(obj, (key, value) => { if (Array.isArray(value)) { value = value.filter((val) => !['', null].includes(val)); } return ['', null].includes(value) || (typeof value === 'object' &&(value.length === 0 || Object.keys(value).length === 0)) ? undefined : value; }); let resObj = JSON.parse(stringfiedObj); let isEmptyPropsPresent = ['{}', '[]', '""', 'null'].some((key) => stringfiedObj.includes(key)) if(isEmptyPropsPresent) { return getPurgedObj(resObj); } return resObj; }
Please share if you have better solution
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
@bharathpanchak Thank you for poiniting out my mistake.
I tried one solution
Please share if you have better solution