if i have 1000+ words as in spanish
in the global variable
 SpanishWord = tres niños
so i want to replace special letters and set as "tres ninos"
i try script 
// Retrieve the value from the global variable 'SpanishWord'
var text = runtime.getGlobalVariable("SpanishWord").getValue();
// Define character mappings for conversion
var charMap = {
 'í': 'i',
 'á': 'a',
 'é': 'e',
 'ó': 'o',
 'ú': 'u',
 'ñ': 'n',
 // Add other mappings as needed
};
// Function to replace characters based on the map
function convertText(text) {
 return text.replace(/[íáéóúñ]/g, function(match) {
 return charMap[match] || match;
 });
}
// Convert the text
var convertedText = convertText(text);
// Set the converted text into the global variable 'spash'
runtime.getGlobalVariable("spash").setValue(convertedText);
but getting error
please guide me right ans..