check if it is object javascript code example
Example 1: javascript check if variable is object
let myObject = {
firstname: 'harry',
lastname: 'potter'
}
console.log(typeof myObject);
if(typeof myObject === 'object') {
console.log('this is object');
}
Example 2: javascript check if object
typeof yourVariable === 'object'
typeof yourVariable === 'object' && yourVariable !== null
Example 3: javascript check if variable is object
function isObject(val) {
if (val === null) { return false;}
return ( (typeof val === 'function') || (typeof val === 'object') );
}
var person = {"name":"Boby Snark"};
isObject(person);