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

180
Vistas
Check if a string exist in array

I have the following key StudentMembers[1].active but I need to check if this key exist in the following array

const array= ["StudentMembers.Active","StudentMembers.InActive"]

How to remove the index [1] from StudentMembers[1].active and check if StudentMembers.Active does exist in the array

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

0

You can use regex to remove all brackets [<any>] like this:

const key = "StudentMembers[1].active".replace(/\[.*\]/, '');
console.log(key); // Return "StudentMembers.active"

Then you can use .find() to check if array contains the key

const array= ["StudentMembers.Active","StudentMembers.InActive"];
const hasKey = array.find(item => item.toLowerCase() == key.toLowerCase()) ? true : false;
console.log(hasKey); // Return true

It is strongly suggested to use .toLowerCase() so it would match any kind of cases.

Example: https://jsfiddle.net/fhkx9v3n/

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