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

277
Views
How to use the JS endswith() method to check if a string variable ends with any one item from an array?

I tried this however it didn't work.

const tlds = [".com", ".net", ".it", ".edu", ".gov"]
ent/*ent is an existing variable in my code*/.endsWith(tlds)

Do I have to make it that it checks through each item in the array?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Yes, you have to make it so that it checks through each item in the array. You could make a for-loop to check all items in the array. Here's my code.

const tlds = [".com", ".net", ".it", ".edu", ".gov"]

function endsWith(string, end) {
  for (let i = 0; i < tlds.length; i++) {
    if (string.endsWith(end[i]) === true) return true
  }
  return false
}

endsWith(ent, tlds)

Hope this helps(;

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!