jQuery.isPlainObject()

jQuery.isPlainObject()

jQuery.isPlainObject( object )Returns: Boolean

Description: Check to see if an object is a plain object (created using "{}" or "new Object").

Note: Host objects (or objects used by browser host environments to complete the execution environment of ECMAScript) have a number of inconsistencies which are difficult to robustly feature detect cross-platform. As a result of this, $.isPlainObject() may evaluate inconsistently across browsers in certain instances.

An example of this is a test against document.location using $.isPlainObject() as follows:

console.log( $.isPlainObject( document.location ) );

which throws an invalid pointer exception in IE8. With this in mind, it's important to be aware of any of the gotchas involved in using $.isPlainObject() against older browsers. A couple basic examples that do function correctly cross-browser can be found below.

Example:

Check an object to see if it's a plain object.

jQuery.isPlainObject({}) // true
jQuery.isPlainObject( "test" ) // false

© The jQuery Foundation and other contributors
Licensed under the MIT License.
https://api.jquery.com/jQuery.isPlainObject

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部