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

174
Views
Reading value of variable in javascript find

I try to read the value of the key color_ids in the following JavaScript associative array:

  const UrlArray = [
    {
      bd_shoe_size_ids: ["6601", "6598"]
    },
    {
      color_ids: ["6056", "6044"]
    },
    {
      manufacturer_ids: ["5875", "5866"]
    }
  ]

This was done by the following code:

UrlArray.find(({color_ids}) => color_ids); 

But I would like to use this code for reading the value of other array keys to. For that I want to store the name of the array key whose value I want to know in a variable. If I use the code below it will of course look for a key called nameOfArrayKey, but is it possible to search for the value of the variable: nameOfArrayKey?

UrlArray.find(({nameOfArrayKey}) => nameOfArrayKey);
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

I had the same problem. Try this:

console.log(UrlArray.map(Object.keys).flat())
about 4 years ago · Juan Pablo Isaza Report

0

you can use hasOwnProperty property to check object has key name

function getObject(urlArray,nameKey){
  const object= urlArray.find(value=>{
     return value.hasOwnProperty(nameKey)
  });
  return object;
}

about 4 years ago · Juan Pablo Isaza Report

0

So, basically, you can try something like this :

const k = "manufacturer_ids"
console.log(UrlArray.find((o) => o[k]))

Output :

{ manufacturer_ids: [ '5875', '5866' ] }
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!