Overview
Check if a value is a plain object created by {} or new Object().
Import
import {utils} from 'metronic-extension';
const {isPlainObject} = utils;
Signature
isPlainObject(payload: any): boolean
| Parameter |
Type |
Description |
payload |
any |
The value to test. |
Returns: boolean — true for plain objects, false otherwise.
Example
<table class="table table-row-bordered" id="isPlainObjectDemo">
<thead><tr class="fw-bold fs-6 text-gray-800"><th>Value</th><th>Result</th></tr></thead>
<tbody></tbody>
</table>
var isPlainObject = metronicExtension.utils.isPlainObject;
var testCases = [
{label: "{}", value: {}},
{label: "{foo: true}", value: {foo: true}},
{label: "new Object()", value: new Object()},
{label: "[]", value: []},
{label: "null", value: null},
{label: "42", value: 42},
{label: "'string'", value: 'string'},
{label: "function(){}", value: function(){}},
{label: "/./", value: /./},
];
var tbody = document.querySelector('#isPlainObjectDemo tbody');
testCases.forEach(function(tc) {
var valid = isPlainObject(tc.value);
var tr = document.createElement('tr');
tr.innerHTML = '<td><code>' + tc.label + '</code></td>'
+ '<td><span class="badge ' + (valid ? 'badge-success' : 'badge-danger')
+ '">' + valid + '</span></td>';
tbody.appendChild(tr);
});