Javascript Uint8ClampedArray map()

Introduction

The Javascript Uint8ClampedArray map() method maps typed array elements by a provided function.

This method works the same as Array.prototype.map().

Uint8ClampedArray.map(mapFn[, thisArg])
Parameter
Optional
Meaning
mapFn




Required




A callback function
Taking three arguments:
currentValue - the current element being processed.
index - Optional, the index of the current element.
array - Optional, the typed array itself.
thisArg
Optional
Value to use as this when executing mapFn.

Mapping a typed array to a typed array of square roots

const numbers = new Uint8ClampedArray([1, 4, 9]);
const roots = numbers.map(Math.sqrt);
console.log(numbers);//from   w ww  .  ja  va2 s. c  o  m
console.log(roots);

Mapping a typed array of numbers using a function containing an argument

const numbers = new Uint8ClampedArray([1, 4, 9]);
const doubles = numbers.map(function(num) {
  return num * 2;
});/*ww  w . j  ava 2  s.c  o  m*/
console.log(numbers);
console.log(doubles);



PreviousNext

Related