{
  "id": 17200754,
  "title": "JavaScript iterations method",
  "url": "https://urgent.news/2026/10/30/javascript-iterations-method",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-30T08:47:25.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/sowntharya/javascript-iterations-method-484n"
  },
  "original_language": "en",
  "account": "JavaScript provides several methods for iterating over arrays. Three primary methods are for...of, for...in, and forEach().\n\nThe for...of loop is used to retrieve the values of an array one by one. For instance, using an array declared as let nums = [10, 20, 30], the for...of loop can be employed as follows: for (let x of nums) { console.log(x) }. This results in output of 10, 20, and 30.\n\nThe for...in loop is utilized for accessing the keys or indexes of an array. However, it is generally not recommended for use with arrays. An example would be: for (let i in nums) { console.log(i) }.\n\nThe forEach() method executes a function for each array element. It does not create a new array. For example, with const numbers = [45, 4, 9, 16, 25], the forEach() method can be used like this: numbers.forEach(myFunction); where myFunction(value) logs the value.\n\nThe map() method creates a new array with the results of calling a provided function on every element in the calling array. For instance, with num1 = [1, 2, 3], and a function myFunction(value) that returns value * 2, num1.map(myFunction) would result in [2, 4, 6].\n\nThe flatMap() method first maps each array element using a mapping function, then flattens the result into a new array. For example, with nums = [1, 2, 3], and a function that returns [n, n * 10], nums.flatMap(n => [n, n * 10]) would produce [1, 10, 2, 20, 3, 30].\n\nThe filter() method creates a new array with all elements that pass the test implemented by the provided function. For example, with nums = [10, 15, 20, 25], nums.filter(myFunction) where myFunction(value) returns value > 15, would result in [20, 25].\n\nThe reduce() method reduces the array to a single value. It works from left to right. For example, with nums = [10, 20, 30], nums.reduce((total, n) => total + n, 0) would result in 60.\n\nThe reduceRight() method is similar to reduce(), but it works from right to left. The every() method checks if all elements satisfy a condition, returning true or false. For instance, with nums = [10, 20, 30], nums.every(n => n > 5) would return true, while nums.every(n => n > 15) would return false.\n\nThe some() method checks if at least one element satisfies a condition, returning true or false. Using the same nums array, some(nums, n => n > 5) would return true, as would some(nums, n => n > 15). Lastly, Array.from() creates a new array from an iterable or array-like value. For example, Array.from(text) where text is 'CAT', would result in ['C', 'A', 'T'].",
  "summary": "JavaScript 3 statement for looping: 1.For...of loop : used to get the values of an array one by one. For array we prefer for...of to get value. let nums = [ 10 , 20 , 30 ]; for ( let x of nums ){ console . log ( x ); } output : 10 20 30 2.for...in loop : used to access the keys or indexes of an array. (Not recommended) let nums = [ 10 , 20 , 30 ]; for ( let i in nums ){ console . log ( i ); }…",
  "key_points": [
    "\"for...of\" iterates over array values",
    "\"forEach()\" executes a function per element",
    "\"reduce()\" condenses array to single value"
  ],
  "editors_take": "Choosing between these diverse iteration methods allows developers to dictate whether they prioritize retrieving individual values, transforming data into new structures, or reducing collections to single results.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}