es-toolkit/docs/reference/compat/util/toPlainObject.md
D-Sketon 622102c9a1
Some checks failed
CI / codecov (push) Has been cancelled
Release / release (push) Has been cancelled
feat(compat): implement toPlainObject (#879)
* feat(compat): implement toPlainObject

* chore: make lint happy
2024-12-08 21:37:16 +09:00

850 B
Raw Permalink Blame History

toPlainObject

::: info This function is only available in es-toolkit/compat for compatibility reasons. It either has alternative native JavaScript APIs or isnt fully optimized yet.

When imported from es-toolkit/compat, it behaves exactly like lodash and provides the same functionalities, as detailed here. :::

Converts value to a plain object flattening inherited enumerable string keyed properties of value to own properties of the plain object.

Signature

function toPlainObject(value: any): Record<string, any>;

Parameters

  • value (any): The value to convert.

Returns

(Record<string, any>): Returns the converted plain object.

Examples

function Foo() {
  this.b = 2;
}
Foo.prototype.c = 3;

toPlainObject(new Foo()); // => { 'b': 2, 'c': 3 }