Two ways to determine if any arrays in an object has an entry
George Jempty

George Jempty @dexygen

About: - Full-stack/front-end web developer since 1999 - Speaker at technical user meetings - Writer of pre-publication technical reviews

Location:
Dallas TX
Joined:
Apr 14, 2018

Two ways to determine if any arrays in an object has an entry

Publish Date: Feb 3 '20
6 0
let pendingAdditions = {
  hospitals: ['Silencio Hospital','St Judes'],
  licenses: ['poe-tic license'],
  medschools: []
}

let somePendingAdditions = Object.values(pendingAdditions).some(arr => arr.length);
console.log(somePendingAdditions); // true
somePendingAdditions = 
    Boolean(Array.prototype.concat.apply([], Object.values(pendingAdditions)).length);
console.log(somePendingAdditions); // true

Pitfalls regarding the second approach noted at: https://stackoverflow.com/questions/60042666/how-to-determine-if-any-arrays-in-an-object-has-an-entry/

Comments 0 total

    Add comment