Javascript BigUint64Array from()

Introduction

The BigUint64Array.from() method creates a new typed array from an array-like or iterable object.

This method works the same as Array.from().

BigUint64Array.from(source[, mapFn[, thisArg]])
Parameter Optional Meaning
sourceRequired 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.
thisArgOptional Value to use as this when executing mapFn.
// Set (iterable object)
const s = new Set([12n, 5n, 8n, 130n, 44n]);
let a = BigUint64Array.from(s);
console.log(a);/*from   ww  w .ja  v a  2s  . c  o m*/

//String
a = BigUint64Array.from('123');
console.log(a);

// Using an arrow function as the map function to manipulate the elements
a = BigUint64Array.from([12n, 5n, 8n, 130n, 44n], x => x + x);
console.log(a);

// Generate a sequence of numbers
a = BigUint64Array.from({length: 5}, (v, k) => k);
console.log(a);



PreviousNext

Related