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

174
Views
get domain substring using javascript

I am trying to parse a domain that has more than two period's in the string.

So for example, I am trying to get sjmktmail-batch1a.marketo.org into marketo.org

I tried using split and a range from the list like this:

testdata = sjmktmail-batch1a.marketo.org
testdata.split(".")[1:2]

but that didn't work. doing testdata.split(".")[1] brings up marketo but I want marketo.org

Sorry, my main language is python, so some javascript concepts confuse me. I assume you can't get a range of an array/list by using [x:x]

My main goal is to get a domain like domain.com

so for example:

fdasdadio.conglomo.com would be conglomo.com billy.fdaoco.codsaso.mainbug.com would be mainbug.com purple.red.bri.noschool.edu would be noschool.edu

Pretty sure I am missing a concept that would make this easy.

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

0

You can do it by a chain of split, slice, join. like this:

slice(-2) means get two last items from array.

const str = 'billy.fdaoco.codsaso.mainbug.com';
const domain = str.split('.').slice(-2).join('.');
console.log(domain)

about 4 years ago · Juan Pablo Isaza Report

0

One line code:

"sjmktmail-batch1a.marketo.org".split('.').slice(1).join('.')

    const input = "sjmktmail-batch1a.marketo.org";
    var data =input.split('.')      // ["sjmktmail-batch1a", "marketo", "org"]
    data = data.slice(1);           // ["sjmktmail-batch1a"]
    const output = data.join('.');  // "marketo.org"
    console.log(output);

about 4 years ago · Juan Pablo Isaza Report

0

It's as easy as splitting the string, and getting the last two elements of the string, right?

var str = "sjmktmail-batch1a.marketo.org"
var arr = str.split(".");
console.log(arr[arr.length-2]+"."+arr[arr.length-1])

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!