判斷空值

Turner發表於2018-12-08
變數: export const isEmpty= key => !key || typeof (key) === 'undefined' || key === null;

陣列: export const isEmptyArray = arr => !arr.length;

物件: export const isEmptyObject = obj => {
if (typeof obj === 'object' && !(obj instanceof Array) && obj !== null) {
  for (let t in obj)
    return false
  }
  return  true
};
複製程式碼

相關文章