toPairs
object
Creates an array of own enumerable string keyed-value pairs for object. This is an alias for entries.
Installation
Import
import { toPairs } from '@tulx/utils';Source Code
Implementation
/**
* Creates an array of own enumerable string keyed-value pairs for object.
* This is an alias for entries.
*
* @param object - The object to query.
* @returns Returns the key-value pairs.
*
* @example
* ```ts
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
* Foo.prototype.c = 3;
* toPairs(new Foo()); // [['a', 1], ['b', 2]]
* ```
*/
export function toPairs<T>(object: Record<string, T>): Array<[string, T]> {
return Object.entries(object);
}
Example
import { toPairs } from '@tulx/utils';
function Foo() {
this.a = 1;
this.b = 2;
}
Foo.prototype.c = 3;
toPairs(new Foo()); // [['a', 1], ['b', 2]]Related Functions
assign
Assigns own enumerable string keyed properties of source objects to the destination object.
assignIn
This method is like assign except that it iterates over own and inherited source properties.
assignInWith
This method is like assignIn except that it accepts customizer which is invoked to produce the assigned values.
assignWith
This method is like assign except that it accepts customizer which is invoked to produce the assigned values.
at
Creates an array of values corresponding to paths of object.
create
Creates an object that inherits from the prototype object.