I am trying to get a classes name through the name of a constructor in a class similar to what they have as the answer for this ask How to get a JavaScript object's class?
What I want to do, is find the item with the id
of 0 and get the second constructor of name
class item {
constructor(id, name, price) {
this.id = id
this.name = name
this.price = price
}
const Bar = new item(0, "Candy bar", "$1")
const Gum = new item(1, "Gum, "$.5")
I need to be able to grab, any id such in this case 1, and use it to find the item's name
So I want to do something close to
var thisItem = item.with.id = 1
console.log(thisItem.name)