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

173
Views
find the character "(" in a string in js

I have a string in my JS that may contain the character (M and I need to find their position - but I can't work out how to without throwing an error I guess due to the bracket.

const findMTag = "(M"; //I need to search for this but it throws an error
let posMTag = nameJoined.search(findMTag);
console.log("TAG position =  " + posMTag);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try with indexOf

const findMTag = "(M"; //I need to search for this but it throws an error
let posMTag = nameJoined.indexOf(findMTag);
console.log("TAG position =  " + posMTag);
about 4 years ago · Juan Pablo Isaza Report

0

String.search accepts a Regular expression as its argument, but you're passing a string to it, so it doesn't work. Take a look at String.search() for more info.

So your code will look like:

const findMTag = /\(M/;
const posMTag = nameJoined.search(findMTag);
console.log("TAG position =  " + posMTag);
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!