Menu

gitpiper

isEmpty javascript Code Snippet in 2023

typearrayobjectstringbeginner

Last Updated: 4 February 2023

Checks if the a value is an empty object/collection, has no enumerable properties or is any type that is not considered a collection.

  • Check if the provided value is null or if its length is equal to 0.
const isEmpty = val => val == null || !(Object.keys(val) || val).length;
isEmpty([]); // true isEmpty({}); // true isEmpty(''); // true isEmpty([1, 2]); // false isEmpty({ a: 1, b: 2 }); // false isEmpty('text'); // false isEmpty(123); // true - type is not considered a collection isEmpty(true); // true - type is not considered a collection

javascript snippet similar to isEmpty For You in February 2023

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2023 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️