The Javascript Uint16Array represents an array of 16-bit unsigned integers in the platform byte order. By default, the contents of Uint16Array are initialized to 0. The Uint16Array.from() function is used to create a new Uint16Array from an array-like or iterable object. So when you want to convert an arrayLike or iterable object then you can use this function by passing the object as a parameter to this function along with the map function and value used for the map function if needed.
Syntax:
Uint16Array.from( source, mapFn, thisArg )
Parameters: This method accepts three parameters as mentioned above and described below.
- source: This parameter is an array-like or iterable object which is used to convert to an Uint16Array object.
- mapFn: This parameter is optional which is the Map function to call on every element of the Uint16Array .
- thisArg: This parameter is optional which is a value to use as this when executing mapFn.
Return Value: This method returns a new Uint16Array instance.
The below examples illustrate the Unit16Array.from() Method in JavaScript:
Example 1: This example shows the basic working of the Unit16Array.from() Method in JavaScript.
javascript
let array = Uint16Array.from('543234543');
console.log(array);
|
Output:
5, 4, 3, 2, 3, 4, 5, 4, 3
Example 2: This example shows the basic working of the Unit16Array.from() Method in JavaScript.
javascript
let array = Uint16Array.from([32,
53, 122, 434, 213], z => z * 3);
console.log(array);
|
Output:
96, 159, 366, 1302, 639
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!
Looking for a place to share your ideas, learn, and connect? Our Community portal is just the spot! Come join us and see what all the buzz is about!
Last Updated :
26 May, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...