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

103
Vistas
Iterate through an array of unknown properties to find a specific value in an object

I'm trying to iterate through an array of unknown properties to find a value that exists within a JSON object although there can exist many objects as well, how can I approach this?

  args1 = ['string', 5, 3, { value: 'value', number: 2, token: 'token' }];
  args2 = [
    'string',
    { token: 'token', name: 'name' },
    1,
    3,
    2,
    { book: 'book' },
  ];

How would i be able to find the property token regardless where it exists like the two examples above?

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

0

May be something like this:

let args1 = ['string', 5, 3, { value: 'value', number: 2, token: 'token' }];

args1.filter(x=> typeof x==='object').find(y => console.log(y.token));
about 4 years ago · Juan Pablo Isaza Denunciar

0

Object.assign can turn everything to a single object, and then you can deal with it in a single way:

const findProp = (arr, prop) => Object.assign({}, ...arr)[prop];

var args1 = ['string', 5, 3, { value: 'value', number: 2, token: 'token' }];
console.log(findProp(args1, "token"));

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