Get Main Field
Retrieves the main field from an item object based on a predefined list of labels to highlight.
Category | Objects |
Author | Pol Gubau |
Since | 1.0.0 |
Last Updated | 2025-03-15 |
Type | Sync |
Compatibility | Universal |
Example
Input
getMainField({ name: 'John Doe', value: 'johndoe123' })
Output:
{ key: 'name', value: 'John Doe' }
Return
Returns an object containing the key and value of the main field.
Type: object
Props
Name | Type | Default | Required | Description |
---|---|---|---|---|
item | Record<string, any> | null | Yes | The item object from which to extract the main field. |
Notes
The function searches for the first label in the `DEFAULT_KEYS` array that exists in the item object. If no label is found, the first key-value pair from the item object is returned instead.
Tags
- object
- field
- main
- label
- extraction
Related
- arrays
- universal
- sync
- Since 1.0.0
- validations
- universal
- sync
- Since 1.0.0
- objects
- universal
- sync
- Since 1.0.0
groupBy
Groups the elements of an array based on a provided key-generating function.
isObject
Checks if the provided parameter is a plain object.
cloneDeep
Deep clone an object. A deep clone is a clone of the source object and all of its children, and their children, and so on.