Lodash _.isPlainObject() Method
Last Updated :
31 Oct, 2023
Lodash _.isPlainObject() method checks if the value is a plain object which means an object created by the Object constructor or one with a [[Prototype]] of null.
Syntax:
_.isPlainObject(value);
Parameters:
This method accepts a single parameter as mentioned above and described below:
- value: It is the function that is used to check the value.
Return Value:
This method returns true if the value is a plain object else false.
Example 1: In this example, we are checking whether the given value is an object or not by the use of the lodash _.isPlainObject() method.
javascript
const _ = require( "lodash" );
let object = _.isPlainObject(Object.create( null ));
let plain_data = (object);
console.log(plain_data);
|
Output:
true
Example 2: In this example, we are checking whether the given value is an object or not by the use of the lodash _.isPlainObject() method.
javascript
const _ = require( "lodash" );
let object = _.isPlainObject([1, 2, 3]);
let plain_data = (object);
console.log(plain_data);
|
Output:
false
Example 3: In this example, we are checking whether the given value is an object or not by the use of the lodash _.isPlainObject() method.
javascript
const _ = require( "lodash" );
let object = _.isPlainObject({ 'x' : 0, 'y' : 0 });
let plain_data = (object);
console.log(plain_data);
|
Output:
true
Note: This code will not work in normal JavaScript because it requires the library lodash to be installed.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...