-3

I have the following object

params: {
  filter: {
     status: '',
     color: 'red'
  }
}

And I need to remove empty/null values from the params object. How can I do that ?

AjjjHsh
  • 253
  • 2
  • 4
  • 11
  • Possible duplicate of [Remove blank attributes from an Object in Javascript](https://stackoverflow.com/questions/286141/remove-blank-attributes-from-an-object-in-javascript) – Calvin Nunes Nov 27 '19 at 19:57

1 Answers1

0

Use Object.keys to iterate through the keys. Use the delete operator when encountering an empty/null value. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete

Make sure to handle cases where an object is nested indeterminately deep.

Our_Benefactors
  • 3,220
  • 3
  • 21
  • 27