jQuery.isPlainObject()S2C Home « Utilities « jQuery.isPlainObject()

Plain object detection.

Description

The jQuery.isPlainObject() jQuery Type utility method, returns a boolean dependant upon the specified object having been created as a plain JavaScript object.

Shorthand version $.isPlainObject()

  • Returns true for objects created using {} or new Object.

Syntax

Signature Description
jQuery.isPlainObject( object )Return a boolean dependant upon the specified object having been created as a plain JavaScript object.

Parameters

Parameter Description Type
objectThe object to test to see if it is a plain JavaScript object.PlainObject

Return

A Boolean object.

jQuery.isPlainObject( object ) ExampleTop

Return a boolean dependant upon the specified object having been created as a plain JavaScript object.

In the example below when we press the button we create some variables and test to see if they are plain JavaScript objects.


$(function(){
  $('#btn2').one('click', function(){
    var obj1 = 'A string', obj2 = [], obj3 = {}, obj4 = new Object;
    $('#div2').append('Is obj1 plain JavaScript object? ' +  $.isPlainObject(obj1) + '<br>');
    $('#div2').append('Is obj2 plain JavaScript object? ' +  $.isPlainObject(obj2) + '<br>');
    $('#div2').append('Is obj3 plain JavaScript object? ' +  $.isPlainObject(obj3) + '<br>');
    $('#div2').append('Is obj4 plain JavaScript object? ' +  $.isPlainObject(obj4) + '<br>');
  });
});

div2. Some initial text.

Press the button below to action the above code: