0

I am trying to search an object for a particular value ("default"), and if found, remove the relevant object.

Object:

{foo: "default", bar: "false"}

Expected Output (Foo Removed):

{bar: "false"}

I believe that the solution lies with .filter but not quite sure..

James
  • 281
  • 3
  • 9
  • You'll find `filter` on arrays, but you don't have and array. Combine the two duplicate questions. Each covers one of the two steps you need to follow. – Quentin Jan 09 '20 at 11:19
  • One way is `Object.keys(input).filter(k => input[k] !== "default").reduce((o, k) => ((o[k] = input[k]), o), {});` if you want to obtain a copy, otherwise find the key and `delete object[key]` after (via `Object.keys(input).find(...)` – Andrea Giammarchi Jan 09 '20 at 11:19
  • @AndreaGiammarchi Thanks very much, I knew the general approach just needed some syntax guidance :), If you post as an answer I can accept.. – James Jan 09 '20 at 11:27
  • I think the operator did a mistake in closing this, as mentioned links don't directly answer your question. However, the latest link have some way to find out the value, and then you cna decide if removing the key, or copy all other values to a new object. Have a look, as I cannot answer in here anymore. – Andrea Giammarchi Jan 09 '20 at 11:37

0 Answers0