let result = 'Apple%00Juice%02';
const removeOne = result.slice(5, 8); // get %00
const removeTwo = result.slice(13, 16); // get %02
slice get the part of I want to remove not I want to get.
Is any function can let me get the result becomes to 'Apple Juice' ?
You can get the desired result using a regex to match the parts you want to remove from the string and then replace them using the replace() method on strings.
const str = "Apple%00Juice%02";
const regex = /%\d+/g;
const result = str.replace(regex, " ").trim()
console.log(result);
Explanation of regex:
% - match the character % literally\d+ - match any digit 0 to 9 one or more times%\d+ - match % character followed by one or more digitsYou can achieve this by using .replace() function
Example:
let result = 'Apple%00Juice%02';
result = result.replace('%00', ' ');
result = result.replace('%02', '');
console.log(result);
Read More About .replace() function at MDN Docs
Edit:
Minifying @Yousaf's Answer
let result = "Apple%00Juice%02";
result = result.replace(/%\d+/g, " ").trim()
console.log(result);
It is possible with replace(), but that is not a sustainable solution. The URL encoding "% 00" is the � ASCII character. This suggests that the string is already being encoded in the wrong character format for the URL. So you have to look at the character format in which your database or file is read out. for example UTF-8, ISO 8859-1
When encoded in the correct character format. Can you decode it in JavaScript using the decodeURIComponent (str) method. more on this