Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
How to find an object key using an variable?

What I want is that my object listen to a string that I send to my function

for example :

const  [object,setobject] = useState([]);
      const HandleChange = (text,field) => {
        if (Object.keys(object).length > 0){ 
          var objects = values + ',' + '{"' +field +'":' + text + '}'
        
          console.log(object[text])
          setobject(objects);
        }
        else {
          var objects = '{"' + field +'":' + '"'+ text + '"}'
          setobject(objects);
          console.log(object[field]);
        } 
      }

from this object(which is a state) I want to get if there is any value equal to variable text inside my object, someone knows how can I find it ?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It seems there several typos in your code (object or objects, console.log(object[text]) or console.log(object[field]), ...).

What I understand is that you wish to access object[field], but object is a String and not an Object.

Following this premise I would suggest converting it to an actual Object first, using JSON.parse(). Then you could check if object[field] already exists.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda