Object.omit
Object.omit
Function
Exclude fields by keyname and return a new object.
Syntax
object.omit(keys) object.omit(key1, key2, ...)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| keys | Array/String | No | [] | Array of keys to exclude, or multiple key parameters. |
Return value
| Type | Description |
|---|---|
| Object | Returns a new object excluding the specified key. |
Return object fields
The returned object contains the fields in the original object that were not excluded. The excluded field does not exist, and the read result is empty; other field values come from the original object.
Example
user = {id: 1, name: 'BT', password: 'x'} result = user.omit('password') // Output: {"id":1,"name":"BT"} print result
Notes
- omit does not modify the original object.
- The returned object maintains the insertion order of the original object.