Skip to content

Instantly share code, notes, and snippets.

@bhaireshm
Last active February 24, 2025 09:26

Revisions

  1. bhaireshm revised this gist Apr 22, 2021. 1 changed file with 6 additions and 16 deletions.
    22 changes: 6 additions & 16 deletions isEmpty.js
    Original file line number Diff line number Diff line change
    @@ -3,20 +3,10 @@
    */

    function isEmpty(data) {
    if (typeof data == "number" || typeof data == "boolean") {
    return false;
    }
    if (typeof data == "undefined" || data === null) {
    return true;
    }
    if (typeof data.length != "undefined") {
    return data.length == 0;
    }
    let count = 0;
    for (let i in data) {
    if (data.hasOwnProperty(i)) {
    count++;
    }
    }
    return count == 0;
    if (typeof data == "number" || typeof data == "boolean") return false;
    if (typeof data == "undefined" || data === null) return true;
    if (typeof data.length != "undefined") return data.length == 0;
    let count = 0;
    for (let i in data) if (data.hasOwnProperty(i)) count++;
    return count == 0;
    }
  2. bhaireshm revised this gist Mar 25, 2021. No changes.
  3. bhaireshm created this gist Mar 25, 2021.
    22 changes: 22 additions & 0 deletions isEmpty.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    /**
    * @param data - any datatype value.
    */

    function isEmpty(data) {
    if (typeof data == "number" || typeof data == "boolean") {
    return false;
    }
    if (typeof data == "undefined" || data === null) {
    return true;
    }
    if (typeof data.length != "undefined") {
    return data.length == 0;
    }
    let count = 0;
    for (let i in data) {
    if (data.hasOwnProperty(i)) {
    count++;
    }
    }
    return count == 0;
    }