Below is a custom String method from How do I replace a character at a particular index in JavaScript?
String.prototype.replaceAt = function(index, replacement) {
return this.substring(0, index) + replacement + this.substring(index + replacement.length);
}
I didn't want the replacement to replace the proceeding characters so I changed it to
String.prototype.replaceAt = function(index, replacement) {
return this.substring(0, index) + replacement + this.substring(index);
}
I was using this to replace the '#' with a '%23' because otherwise the browser doesn't understand the link at gives a 404 error (I am programming this on a localhost server).
My fileNames
array looks like
const fileNames = [
["template.html", "first.php", "second.php", "comments.php", "predefined.php", "strings.php", "concat.php",
"numbers.php", "constants.php", "quotes.php"],
["form.html", "handle_form #1.php", "handle_form #2.php", "handle_form #3.php"],
[""],
[""],
[],
[],
];
Then I loop through the 2-D array. Finally, I loop through each string in fileNames with another loop. If the following code is commented out it works fine but the task that the code accomplishes is not carried out.
for (let k = 0; k < fileNames[i][j].length; k++) {
if (fileNames[i][j][k] == '#') {
fileNames[i][j] = fileNames[i][j].replaceAt(k, '%23');
}
}
}
}
The problem is as soon as I change index + replacement.length
to index
, the page stops loading and a popup shows up saying the page is unresponsive. Why is this happening? How do I fix it?