The string.at method lets you get characters in a string by index, much like using a bracket accessor. However string.at also accepts negative indexes. These count backwards from the end of the string.
To get the last character in a string, simply call myString.at(-1). Keep in mind that if the string does not contain enough characters, string.at will return undefined for both positive and negative indexes.
PS: Technically bracket accessors and string.at do not return characters but instead return strings created from code points at the given index. This is important to understand when working with emoji and multibyte characters.
#javascript
In questa pagina del sito puoi guardare il video online JavaScript tips — Using string.at(-1) to get the last character in a string della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Code 2020 07 dicembre 2022, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 960 volte e gli è piaciuto 23 spettatori. Buona visione!