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

151
Vistas
Get index of name in 2d array with names separated by commas

I have the following 2d array:

 const sample = [
   ['Name 1', 'Name 2, Name 3', 'Name 4'],
   ['', 'Name 5', 'Name 6, Name 7'],
   ['Name 8, Name 9', 'Name 10', '']
 ]

As you can see, some strings have more than one name (separated by a comma)

I have the following function that return true if input name has an index of 0 or 1 otherwise it returns false:

function indexIsZeroOrOne(arr, name) {
    for (const row of arr) {
        const i = row.indexOf(name)
        if (i === 0 || i === 1) {
          return true
        }  
    }
    return false
  }

It works with strings that have a single name but not with those with multiple names.

How to modify this so that calling, for example: console.log(indexIsZeroOrOne(sample, 'Name 2') would return true?

about 4 years ago · Juan Pablo Isaza
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