Overview
Check if a value is empty. Returns true for blank strings, null, undefined, NaN, empty arrays, empty objects, empty File, empty Set, and empty Map.
Import
import {utils} from 'metronic-extension';
const {isEmpty} = utils;
Signature
isEmpty(payload: any): boolean
| Parameter |
Type |
Description |
payload |
any |
The value to test. |
Returns: boolean — true if empty, false otherwise.
Example
<div class="mb-3">
<label class="form-label">Input value</label>
<input id="isEmptyInput" class="form-control form-control-solid" placeholder="Enter a value..." value="">
</div>
<div>
<span class="fw-bold">Result: </span>
<span id="isEmptyResult" class="badge badge-success">true</span>
</div>
var isEmpty = metronicExtension.utils.isEmpty;
var input = document.getElementById('isEmptyInput');
var result = document.getElementById('isEmptyResult');
function update() {
var valid = isEmpty(input.value);
result.textContent = valid ? 'true' : 'false';
result.className = 'badge ' + (valid ? 'badge-success' : 'badge-danger');
}
input.addEventListener('input', update);
update();