Last Updated : 09 Dec, 2022
The Javascript Uint8ClampedArray array is an array of 8-bit unsigned integers clamped to 0-255. If the value passed is less than 0 or larger than 255 then it will be set instead. If a non-integer is specified, the nearest integer will be set.
The Uint8ClampedArray.of() method creates a new typed array from a variable number of arguments.
Syntax:
Uint8ClampedArray.of(el0, el1, el2, ..., eln)
Parameters:
Return Value: This method returns a new Uint8ClampedArray instance.
Example 1: In this example, the values passed are the character values that are converted to Uint8Clamped by the method.
JavaScript
<script>
// Creating a Uint8ClampedArray from
// an array by creating the array from
// the Uint8ClampedArray.of() method
let uint8CArr = new Uint8ClampedArray;
uint8CArr = Uint8ClampedArray.of(
'40', '51', '56', '18', '24');
// Printing the result
console.log(uint8CArr);
</script>
Output:
Uint8ClampedArray(5) [40, 51, 56, 18, 24]
Example 2: In this example, the values passed are the int values that are converted to Uint8Clamped by the method. -9999 and 799 converted to 0 and 255 respectively.
JavaScript
<script>
// Creating a Uint8ClampedArray from
// an array by creating the array from
// the Uint8ClampedArray.of() method
let uint8CArr = new Uint8ClampedArray;
// Accepts the uint8C values
uint8CArr = Uint8ClampedArray.of(
-9999, 50, 7, 799, 8);
// Print the result
console.log(uint8CArr);
</script>
Output:
Uint8ClampedArray(5) [0, 50, 7, 255, 8]
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