如何判断一个对象为空对象

如何判断一个对象为空对象

  • JSON.stringify({}) === '{}'

  • Object.keys({}).length === 0

  • for in循环

如何判断一个变量是不是数组

let arr = [1, 1, 2];
console.log(Array.isArray(arr));
console.log(arr instanceof Array);
console.log(Object.prototype.toString.call(arr) === "[object Array]");
console.log([].constructor);
原文地址:https://www.cnblogs.com/ndh074512/p/15400080.html