A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/javascript-unit16array-from-method/ below:

JavaScript Unit16Array.from() Method - GeeksforGeeks

JavaScript Unit16Array.from() Method

Last Updated : 12 Jul, 2025

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.

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
// Create a Uint16Array from a string
// like structure
let array = Uint16Array.from('543234543');

// Print the result
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
// Create a Uint16Array from a array
// multiplying 3 to each number
// using function
let array = Uint16Array.from([32,
    53, 122, 434, 213], z => z * 3);

// Print the result
console.log(array);

Output:

96, 159, 366, 1302, 639


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4