[Vuejs]-How to replace part of a string with a const?

0👍

I finally found my problem.

I was having umlauts(ö, ä, ü) in my searchTerm so I had to use encodeURI() on my searchTerm first.

0👍

try this to remove search param:

const url = 'https://example.com/posts?page=5&sort=desc';

const urlObj = new URL(url);

urlObj.search = '';

const result = urlObj.toString();

console.log(result); // https://example.com/posts

source

-2👍

Use substring() function to get the part you want and use replace() to replace it with whatever you want

const const1 = "adios";
const const2 = "muchasgracias";
var result = const2.replace(const2.substring(0,5), const1);
console.log(result);

Leave a comment