Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript check if variable is object

let myObject = {
	firstname: 'harry',
  	lastname: 'potter'
}
//check the typeof if, boolean, object, string etc...
console.log(typeof myObject);
if(typeof myObject === 'object') {
	console.log('this is object');
}
Comment

javascript check if variable is object

//checks if is object, null val returns false
function isObject(val) {
    if (val === null) { return false;}
    return ( (typeof val === 'function') || (typeof val === 'object') );
}
var person = {"name":"Boby Snark"};
isObject(person);//true
Comment

javascript check if object

typeof yourVariable === 'object' // true if it's an object or if it's NULL.

// if you want to exclude NULL
typeof yourVariable === 'object' && yourVariable !== null
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript convert object to querystring 
Javascript :: background image in react from variable 
Javascript :: how to merge 2 object array by the same key with lodash 
Javascript :: get bottom position of element javascript 
Javascript :: on refresh react url not working or 404 page not showing react 
Javascript :: find specific word string js 
Javascript :: jquery mobile or desktop 
Javascript :: remove specific element from array javascript 
Javascript :: react antd form disable submit button 
Javascript :: jquery child selector 
Javascript :: Update multiple documents by id set. Mongoose 
Javascript :: referenceerror document is not defined node js 
Javascript :: javascript inject html 
Javascript :: chart js radar grid color 
Javascript :: round decimal js 
Javascript :: node main 
Javascript :: remove duplicates from array of objects 
Javascript :: import bootstrap in react 
Javascript :: render markdown in nextjs 
Javascript :: (Unauthorized) not authorized on admin to execute command 
Javascript :: install javascript kali linux 
Javascript :: password confirmation using Joi 
Javascript :: i18n vue cli 
Javascript :: counter in javascript 
Javascript :: jquery set select value 
Javascript :: toarray javascript 
Javascript :: jquery find index of this 
Javascript :: jquery get duration video tag 
Javascript :: CastError: Cast to ObjectId failed for value "undefined" at path "_id" for model 
Javascript :: empty function after it is run javascript 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =