Recursively remove null values from JavaScript object

前端 未结 8 839
挽巷
挽巷 2020-12-28 16:07

I have a JSON obj, after some operations (like delete some pieces), I print it and everything looks good except that I have some null values. How do I remove th

8条回答
  •  礼貌的吻别
    2020-12-28 16:21

    I use the code here

    Remove empty elements from an array in Javascript

    then you could call it like

    JSON.stringify(obj.clean(null), null, 2)

    You would need to modify the code to work with objects too (or use the code as is inside the objects)

提交回复
热议问题