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

162
Views
How to use splice on string in JavaScript

I wish to use splice on string e.g.

console.log(removeFromString('Elie', 2, 2)) // 'El'
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

If you really want to use splice(), you can spread the string to an array, invoke splice() on the array, and join() the results back together:

const removeFromString = (s, x, y) => {
  const array = [...s];
  array.splice(x, y);
  return array.join('');
}

console.log(removeFromString('Elie', 2, 2));

about 4 years ago · Juan Pablo Isaza Report

0

I think this is what you want to do.

function removeFromString(string, start, count) {
    let str = string.split('');
    str.splice(start, count);
    return str.join('');
}

console.log(removeFromString('Elie', 2, 2));

about 4 years ago · Juan Pablo Isaza Report

0

Try this:

function removeFromString(str, start, end) {
  let arr = Array.from(str);
  arr.splice(start, end);
  return arr.join(String());
}

and then use:

removeFromString('Elie', 2, 2);
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!