“JavaScript prüfen, ob eine Variable Objekt ist” Code-Antworten

JavaScript prüfen, ob eine Variable Objekt ist

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');
}
Excited Elk

JavaScript prüfen, ob eine Variable Objekt ist

//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
Grepper

JavaScript prüfen, ob Objekt

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
Web Surfer

Ähnliche Antworten wie “JavaScript prüfen, ob eine Variable Objekt ist”

Fragen ähnlich wie “JavaScript prüfen, ob eine Variable Objekt ist”

Weitere verwandte Antworten zu “JavaScript prüfen, ob eine Variable Objekt ist” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen