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

81
Views
Get value by key from array of array - Javascript

I have a meta as below:

obj = {
   meta: [['type', 'test1'], ['key2', 'value2']],
   value: 'text1',
}

Want to read value test by passing the key type

expected result is test1

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You could use Object.fromEntries()

const obj = {
   meta: [['type', 'test'], ['key2', 'value2']],
   value: 'text1',
}

const key = 'type'

const res = Object.fromEntries(obj.meta)[key];

console.log(res)

about 4 years ago · Juan Pablo Isaza Report

0

You should restructure meta as an object instead of an array of pairs as:

obj = {
   meta: {
        'type': 'test',
        'key2': 'value2'
   }
   value: 'text1',
}

Now, you can access what you need as obj['meta']['type'] or obj.meta.type.

about 4 years ago · Juan Pablo Isaza Report

0

obj = {
   meta: [['type', 'test'], ['key2', 'value2']],
   value: 'text1',
}

  for(let arr of obj.meta){
      if(arr[0]==='type'){
        return arr[1];
    }
 }

or

const res=obj.meta.find(arr=>arr[0]==="type");
if(res && res.length) return res[1]

Notice that this code returns only the first "type". If you have "type" twice you'll get the first result.

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!