Skip to content

isPlainObject() function

value がプレーンオブジェクト(plain object)かどうかを確認します。つまり、プロトタイプが Object.prototype であるオブジェクト(例: オブジェクトリテラル、new Object())、または null であるオブジェクト(Object.create(null))かどうかを判定します。

配列や関数を含むすべての非プリミティブ値に対して true を返す isObject とは異なり、isPlainObject は配列、関数、クラスインスタンス、そして DateMapSet などの組み込みオブジェクトに対して false を返します。

Signature:

typescript
isPlainObject: (value: unknown) => value is Record<PropertyKey, unknown>

Example

ts
isPlainObject({}); // true
isPlainObject({ a: 1 }); // true
isPlainObject(Object.create(null)); // true
isPlainObject([1, 2, 3]); // false
isPlainObject(() => {}); // false
isPlainObject(new Date()); // false
isPlainObject(null); // false
isPlainObject(123); // false

Open Source Code

Released under the Apache-2.0 License.