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

80
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 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