Let's assume that we are working with a spanish text and we want to know whether a certain word has accent or not.
// Sample text let sentence = 'Erik Martín es un desarrollador de software.'; // Defining accent chars let accentChars = ['á', 'é', 'í', 'ó', 'ú']; // Detecting if the text has accents let textHasAccents = accentChars.some(char => sentence.includes(char)); // Filtering words with accents let wordsWithAccents = sentence.split(' ').filter(word => accentChars.some(char => word.includes(char))); console.log(textHasAccents); // true console.log(wordWithAccents); // ['Martín']
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.