FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Medium

Deep Omit

30mins

Implement a function deepOmit(obj, keys) that removes specified keys and their corresponding values from an object, including nested objects or arrays.

The function should:

  • Accept an object obj.
  • Accept an array of string keys keys.
  • Recursively traverse the object and nested objects/arrays to remove all occurrences of the specified keys.

Example

deepOmit({ a: 1, b: 2, c: 3 }, ['b']); // { a: 1, c: 3 } const obj = { a: 1, b: 2, c: { d: 3, e: 4, }, f: [5, 6], }; deepOmit(obj, ['b', 'c', 'e']); // { a: 1, f: [5, 6] }

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests