Get the App
SLTechnology News&Howtos  ›  Development  › 

How js converts array elements to numbers

Shulou Source: shulou.com Published: 2022-06-01 05:55:26 10月14日 Update

This article is about how js converts array elements to numbers. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Convert array elements to numbers

If you have an array and want to convert the elements in the array to numbers, you can use the map method to do this:

Const array = ['12,'1, '3.1415,'-10.01]; array.map (Number); / / [12, 1, 3.1415,-10.01]

In this way, map executes the Number constructor on each element of the array and returns the result as it traverses the array.

Thank you for reading! This is the end of the article on "how js converts array elements into numbers". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Arrays elements numbers content more articles good practical functions articles ways methods see knowledge results references help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Xiaomi macOS Linux MariaDB