Octagram Labs
JavaScriptData StructuresReact
Sign in
← Back to problems

Remove a Field

Immutable Stateeasy

Course · Section 9: Data Structures, Modern Operators and Strings · Lecture 111: The Spread Operator (...)

Implement `removeField(state, key)` returning a new object without `key`.

Sample tests

Input: removeField({"a":1,"b":2}, "a")
Output: {"b":2}
Input: removeField({"a":1}, "x")
Output: {"a":1}

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • delete state[key] mutates the original object.

Learning resources

  • React: Updating Objects in State
Approach & explanation (try first)

Copy with { ...state } and delete the key from the copy so the original state object is never touched.

Loading...
⌘/Ctrl + Enter

Run your code to see results.