![]() |
The BigUint64Array() Constructor creates a new typed array of the 64-bit unsigned integers (BigInts). Typed arrays are a way to handle and manipulate binary data in a specific format. It allows to create arrays for storing large unsigned 64-bit integers. It is part of the JavaScript TypedArray object family which provides efficient memory management and manipulation of the binary data. The JavaScript’s native number type is limited to a 53-bit precision, which means it cannot accurately represent integers beyond that range. However, some applications such as cryptography or low-level data manipulation require operations on larger numbers. The BigUint64Array comes in handy for handling these scenarios. Syntax: new BigUint64Array(length); The BigUint64Array() constructor creates a new BigUint64Array object with a specified length or based on the existing typedArray, object, or buffer. Parameters: This constructor passes the following parameters:
Return Value: A new BigUint64Array object with the specified length or with the elements copied from provided typedArray or object. Usage:
// Creates a BigUint64Array with the 5 elements initialized to 0
// Creates a BigUint64Array with same values as existingArray
// Creates a BigUint64Array with the values from iterable object
// Creates a BigUint64Array with 4 elements, starting at byte offset 8. Example 1: Creating an empty BigUint64Array with a specific length. Javascript
Output: BigUint64Array(2) [ 0n, 0n ] Example 2: Creating a BigUint64Array from an iterable object (e.g., an array). Javascript
Output: BigUint64Array(3) [ 150n, 210n, 400n ] Example 3: Accessing a subset of a BigUint64Array Javascript
Output: BigUint64Array(2) [ 300n, 200n ] Example 4: Modifying a BigUint64Array element Javascript
Output: BigUint64Array(3) [ 20n, 30n, 50n ] Supported Browsers:
In Conclusion, The BigUint64Array() Constructor provides a way to work with large unsigned 64-bit integers in an array-like structure. It allows you to create and manipulate arrays of these large integers, enabling operations on numbers that exceed the usual JavaScript numeric limits. Whether you need to handle cryptographic operations, bit manipulation, or other scenarios requiring large integer arithmetic. BigUint64Array provides a useful tool in JavaScript. |
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |