DekGenius.com
JAVASCRIPT
get name of class javascript
javascript get class name
document.getElementById("myDIV").className = "mystyle";
How to get the Class Name of an Object in JavaScript
class Language {}
const l1 = new Language();
console.log(l1.constructor.name);
How to get the Class Name of an Object in JavaScript
const Season = [
{
month:'January',
season: 'Winter',
},
{
month:'March',
season: 'Spring',
},
{
month:'June',
season: 'Summer',
},
{
month:'August',
season: 'Autumn',
},
]
const index = Season.findIndex( (loopVariable) => loopVariable.month === 'March');
console.log("The index of March Month is",index)
How to get the Class Name of an Object in JavaScript
const Season = [
{
month:'January',
season: 'Winter',
},
{
month:'March',
season: 'Spring',
},
{
month:'June',
season: 'Summer',
},
{
month:'August',
season: 'Autumn',
},
]
const index = Season.map( (loopVariable) => loopVariable.month).indexOf
("March"));
console.log("The index of March Month is",index)
how to get class name of element in javascript
var spans = document.getElementsByTagName("span");
for (var i = 0; i < spans.length; i++) {
if (spans[i].className == 'xyz') {
spans[i].style.backgroundColor = '#000';
}
}
get class name object
class Language {}
const l1 = new Language();
console.log(l1.constructor.name); //Language
// Works too
(1)?.constructor.name // "Number"
(false)?.constructor.name // "Boolean"
(1)?.constructor.name // "Number"
("aa")?.constructor.name // "String"
([])?.constructor.name // "Array"
({a:"a"})?.constructor.name // "Object"
(false)?.constructor.name // "Boolean"
(null)?.constructor.name // undefined
(document)?.constructor.name // "HTMLDocument"
(myImageElement)?.constructor.name // "HTMLImageElement"
How to get the Class Name of an Object in JavaScript
class Language {
getClassName() {
return this.constructor.name;
}
}
const l1 = new Language ();
const objClassName = l1.getClassName();
console.log(objClassName);
Get class name of object JavaScript
var what = function(obj) {
return obj.toString().match(/ (w+)/)[1];
};
get class of object javascript
class Dog{}
var dog = new Dog();
if(dog instanceof Dog){
console.log("Is dog");
}
© 2022 Copyright:
DekGenius.com