If typeof yourVariable === 'object'
, it's an object or null
.
If you want null
, arrays or functions to be excluded, just make it:
if (
typeof yourVariable === 'object' &&
!Array.isArray(yourVariable) &&
yourVariable !== null
) {
executeSomeCode();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…