The Float32Array.from()
method creates a new typed array from an array-like or iterable object.
This method works the same as Array.from()
.
Float32Array.from(source[, mapFn[, thisArg]])
Parameter | Optional | Meaning |
---|---|---|
source | Required | An array-like or iterable object to convert to a typed array. |
mapFn | Optional | Map function to call on every element of the typed array. |
thisArg | Optional | Value to use as this when executing mapFn . |
// Set (iterable object) const s = new Set([1, 2, 3]);/*from w w w . j av a2 s . c o m*/ let a = Float32Array.from(s); console.log(a); //String a = Float32Array.from('123'); console.log(a); // Using an arrow function as the map function to manipulate the elements a = Float32Array.from([1, 2, 3], x => x + x); console.log(a); // Generate a sequence of numbers a = Float32Array.from({length: 5}, (v, k) => k); console.log(a);