class ResistorColor {
private colors: string[]
public colorValues = {
black: 0,
brown: 1,
red: 2,
orange: 3,
yellow: 4,
green: 5,
blue: 6,
violet: 7,
grey: 8,
white: 9
}
constructor(colors: string[]) {
if( colors.length > 2)
{
for( key in this.colorValues)
{
if (this.colorValues[key].indexOf(colors[0]) !== -1)
{
return key;
}
}
}
this.colors = colors
}
}
Idea is to find whether the color that has been input by the user is present in the object colorValues or not.
I referred to this: Find a value in a JavaScript object
I am getting the error of cannot find name key. I am using a Typescript, online editor.
Please explain to me what am I doing wrong here.
a.indexOf(v) !== -1usea.includes(v).