Open In App

Lodash _.isPlainObject() Method

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:



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.






// Requiring the lodash library
const _ = require("lodash");
 
// Original array
let object = _.isPlainObject(Object.create(null));
 
// Using the _.isPlainObject() method
let plain_data = (object);
 
// Printing the output
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.




// Requiring the lodash library
const _ = require("lodash");
 
// Original array
let object = _.isPlainObject([1, 2, 3]);
 
// Using the _.isPlainObject() method
let plain_data = (object);
 
// Printing the output
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.




// Requiring the lodash library
const _ = require("lodash");
 
// Original array
let object = _.isPlainObject({ 'x': 0, 'y': 0 });
 
// Using the _.isPlainObject() method
let plain_data = (object);
 
// Printing the output
console.log(plain_data);

Output:

true

Note: This code will not work in normal JavaScript because it requires the library lodash to be installed.


Article Tags :