How to use TypedArray.forEach() to execute a provided function once per typed array element in JavaScript

1 Answer

0 votes
// typedarray.forEach(callback[, thisArg])

function forEach_function(element, index, array) 
{
  document.write('arr[' + index + '] = ' + element + "<br />");
}

var arr = new Uint8Array([10, 7, 13, 14, 31, 100]).forEach(forEach_function);

/*
run:

arr[0] = 10
arr[1] = 7
arr[2] = 13
arr[3] = 14
arr[4] = 31
arr[5] = 100

*/

 



answered Aug 13, 2016 by avibootz
...