Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!