Which method is commonly used to iterate through elements of an array in JavaScript?
- for...in loop
- forEach() method
- while loop
- map() method
The forEach() method is commonly used to iterate through elements of an array in JavaScript. It allows you to execute a provided function once for each array element, making it a straightforward choice for looping through arrays. The other options, such as for...in loop, while loop, and map() method, have different use cases and are not the most common choices for simple array iteration.
Loading...
Related Quiz
- What will be the length of the array after [1, 2, 3].unshift(4, 5);?
- What is the output of the arithmetic expression 7 / 0 in JavaScript?
- A ________ object represents a group of response headers, allowing you to query them and take different actions depending on the results.
- In which context does the "this" keyword not refer to the object that calls the function?
- To change the content of an HTML element, you can use textContent or _________.