Javascript – Fill in the input with the object key

Hello Silvio.

You can do:

var object = {
10: 0.9997,
11: 0.9996,
12: 0.9995
}

Function showValue (value) {
var boxValue = document.getElementById ("value field")
if (object type[valor] ! == "undefined") {
boxValue.value = object[valor]
    } else {
boxValue.value = "Value not found"
}
}

key

value

In this code, we get the value entered in the text box for each event keyup happens in it Since this number is the key of the value searched for in the object, object[chave] and we will have the desired value. Then print this value as desired in the other text box.

In addition, if we insert a key that matches a value that does not exist in our object, we get one undefined when we do it object[chave], To display an error message to the user, we can perform an if check if object[chave] is an undefined type.