Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!