如何检查一个值是否是 JavaScript 中的对象?
最佳答案
如果typeof yourVariable === 'object'
,它是一个对象或null
。
如果你想排除null
、数组或函数,就这样吧:
if (
typeof yourVariable === 'object' &&
!Array.isArray(yourVariable) &&
yourVariable !== null
) {
executeSomeCode();
}
关于javascript - 检查一个值是否是 JavaScript 中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44107000/