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

134
Vistas
Javascript find dictionary items whose key matches a substring in an optimized way

Consider the below scenario

const searchString = 'Gen';

const myDict = {
'Genesis': 'You are the beginning',
'Joel': 'Joe is cool'
 // Many other key value pairs
}

I need to get You are the beginning because searchString(Gen) is a substring of Genesis.

How can I achieve this in an optimized way in JS?

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

0

You could do something like:

const searchString = 'Gen';

const myDict = {
'Genesis': 'You are the beginning',
'Joel': 'Joe is cool'
 // Many other key value pairs
}


for (let key in myDict){
    if(key.includes(searchString)){
        console.log(myDict[key]) // You are the beginning
    }
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

You could use find()

const searchString = 'Gen';

const myDict = {
'Genesis': 'You are the beginning',
'Joel': 'Joe is cool'
 // Many other key value pairs
}

const result = Object.entries(myDict).find(([k]) => k.includes(searchString));

console.log(result[1]);

about 4 years ago · Juan Pablo Isaza Denunciar

0

const searchString = 'Gen';

const myDict = {
'Genesis': 'You are the beginning',
'Joel': 'Joe is cool'
 // Many other key value pairs
}

const result = Object.entries(myDict).find(([k]) => k.includes(searchString));

console.log(result[1]);

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