Sunday, October 12, 2025
HomeLanguagesJavascriptJavaScript typedArray.forEach() Method

JavaScript typedArray.forEach() Method

The typedArray.forEach() is an inbuilt function in JavaScript which executes a given function once for each given typedArray element. 

Syntax:

typedarray.forEach(callback)

Parameter: It accepts a parameter “callback” function which produces each element of the new typedArray and this function takes three parameters that are specified below-

  • currentValue: It is the value of the current element which is being processed in the typedArray.
  • index: It is the index of the current element being processed in the array.
  • array: It is the array on which the forEach() function is being called.

Return Value: It does not return anything. 

Example:

javascript




// Constructing some typedArray
const A = new Uint8Array([ 1, 3, 5, 7 ])
const B = new Uint8Array([ 2, 4, 6, 8 ])
  
// Calling callback function
function callback(element, index, array) {
    console.log('a[' + index + '] = ' + element);
}
  
// Calling forEach() function
A.forEach(callback);
B.forEach(callback);


Output:

a[0] = 1
a[1] = 3
a[2] = 5
a[3] = 7
a[0] = 2
a[1] = 4
a[2] = 6
a[3] = 8
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!
RELATED ARTICLES

Most Popular

Dominic
32352 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6720 POSTS0 COMMENTS
Nicole Veronica
11885 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6840 POSTS0 COMMENTS
Ted Musemwa
7105 POSTS0 COMMENTS
Thapelo Manthata
6795 POSTS0 COMMENTS
Umr Jansen
6795 POSTS0 COMMENTS