Object.from_entries
Object.from_entries
Function
Create an object from an array of [key, value] entries.
Syntax
object.from_entries(entries)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| entries | Array | No | Current object entries | [key, value] Array of entries. |
Return value
| Type | Description |
|---|---|
| Object | The new object created. |
Return object fields
Return object fields from valid [key, value] entries. The first item of each entry will be converted into the field name, and the second item will be used as the field value; the entry that appears after pressing the field with the same name overwrites the previous entry.
Code Example
result = {}.from_entries([['name', 'BT'], ['age', 1]]) // Output: {"name":"BT","age":1} print result
Notes
- Invalid entries will be skipped.
- The entry that appears after pressing the key with the same name overwrites the previous entry.