8/30/2023 0 Comments Convert to number javascript![]() We can use the map() method more explicitly like this: const str = '1,2,3,4' Ĭonst nums = str.split(',').map((item) => Number(item)) We pass the Number constructor to map(), so Number() will be called on each string in the array to convert it to a number. The Array map() method creates a new array from the result of calling a callback function on each element of the original array. We pass a comma to separate the stringified numbers into separate elements in the resulting array. The String split() method divides a string into an array of characters using the specified separator. Then use the map() method to transform each string in the array into a number.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |