Logo

Programming-Idioms

History of Idiom 169 > diff from v97 to v98

Edit summary for version 98 by doinkythederp:
New JS implementation by user [doinkythederp]

Version 97

2021-12-23, 09:11:52

Version 98

2022-01-22, 23:22:20

Idiom #169 String length

Assign to integer n the number of characters of string s.
Make sure that multibyte characters are properly handled.
n can be different from the number of bytes of s.

Idiom #169 String length

Assign to integer n the number of characters of string s.
Make sure that multibyte characters are properly handled.
n can be different from the number of bytes of s.

Variables
n,s
Variables
n,s
Extra Keywords
size characters chars number runes
Extra Keywords
size characters chars number runes
Code
const n = [...s].length;
Comments bubble
Sets n to the count of characters in s, not the number of bytes.
Doc URL
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length#unicode