Skip to content
Related Articles

Related Articles

Improve Article
JavaScript | Float32Array.from() Method
  • Last Updated : 29 Jan, 2020

The Float32Array array represents an array of 32-bit floating-point numbers in the platform byte order. By default, the contents of Float32Array are initialized to 0.

The Float32Array.from() method is used to create a new Float32Array from an array-like or iterable object. So when you want to convert an arrayLike or iterable object to Float32Array then you can use this function by passing the object as a parameter to this function along with map function and value used for map function if needed.


Float32Array.from( source, mapFn, thisArg )

Parameters: This method accept three parameters as mentioned above and described below.

  • source: This parameter is an array-like or iterable object which is used to convert to a Float32Array object.
  • mapFn: This parameter is an optional which is Map function to call on every element of the Float32Array array.
  • thisArg: This parameter is optional which is value to use as this when executing mapFn.

Return Value: This method returns a new Float32Array instance.

Below examples illustrate the Float32Array.from() Method in JavaScript:

Program 1:

// Create a Float32Array from a string like structure
var  array = Float32Array.from('7654312456754');
// Print the result


7, 6, 5, 4, 3, 1, 2, 4, 5, 6, 7, 5, 4

Program 2:

// Create a Float32Array from an array by
// multiplying 33.32 to each number using
// function
var  array = Float32Array.from([5232.4242,
        3114.24551], z => z  * 33.32);
// Print the result


174344.375, 103766.6640625


My Personal Notes arrow_drop_up
Recommended Articles
Page :