how to check if typeof object is key value in 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 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);