0

I have a url that contains a parameter, which I want to remove. I have created an if...else condition, but I would like to improve it in ES6.

if ( window.location.search.indexOf('&submit')  > -1 ) {
    window.location = urlBase + '/' + window.location.search;
} else {
    window.location = urlBase + '/' + window.location.search + '&submit=1';
}

Thank you in advance.

2
  • What would you hope that ES6 could improve in this code? Commented Mar 30, 2017 at 14:09
  • I want just know if possible to reduce this condition. Commented Mar 30, 2017 at 14:10

1 Answer 1

3

Not sure what your goal is, but here I've simply used includes and template literals.

if (window.location.search.includes('&submit')) {
    window.location = `${urlBase}/${window.location.search}`;
} else {
    window.location = `${urlBase}/${window.location.search}&submit=1`;
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.