Hello and welcome to my first article! As a tech newbie myself, I understand how daunting it can be to dive into the world of technology. But fear ...
For further actions, you may consider blocking this person and/or reporting abuse
Using split('') might not work well with Unicode characters, especially with characters outside the Basic Multilingual Plane (BMP). To properly handle Unicode characters, you can use the Array.from() method to create an array of characters while preserving the Unicode characters.
function reverseString(str) {
return Array.from(str).reverse().join('');
}
To reverse a unicode string you need an iterator over the grapheme clusters.
String.prototype[@@iterator]() - JavaScript | MDN
The @@iterator method of a string implements the iterable protocol and allows strings to be consumed by most syntaxes expecting iterables, such as the spread syntax and for...of loops. It returns an iterator that yields the Unicode code points of the string value as individual strings.
Using
:str.split('')
does not work at all well with Unicode characters.[...str]
is much better, but still not perfect.grapheme-splitter
Intl.Segmenter - JavaScript | MDN
The Intl.Segmenter object enables locale-sensitive text segmentation, enabling you to get meaningful items (graphemes, words or sentences) from a string.
String - JavaScript | MDN
The String object is used to represent and manipulate a sequence of characters.
Yup, I was too tired to go into these last night 👍
Awesome API! Shame it's missing in FF
It only became part of the Internationalization API Specification (ECMA 402) with ES2022.
bugzilla.mozilla.org/show_bug.cgi?...
write your snippet like "
javascript" instead of just "
". It's hard to read without syntax colors.
This is awesome!
Thank you.
Super helpful!