nall
0
Q:

what is the modern syntax for iterating through array using for loop in javascript

<script> 
index = 0; 
array = [ 1, 2, 3, 4, 5, 6 ]; 
  
array.forEach(myFunction); 
function myFunction(item, index) 
{ 
    console.log(item); 
}</script>
3
const people = [ {name: "john", age:23},
                {name: "john", age:43},
                {name: "jim", age:101},
                {name: "bob", age:67} ];

const john = people.find(person => person.name === 'john');
console.log(john);
0
const myArray = [{x:100}, {x:200}, {x:300}];

const sum = myArray.map(element => element.x).reduce((a, b) => a + b, 0);
console.log(sum); // 600 = 0 + 100 + 200 + 300

const average = sum / myArray.length;
console.log(average); // 200
0
let friends=["jony","tom","Tejas"];
       friends.forEach(
           function f(i){
               console.log(i);
           }
       )
0

New to Communities?

Join the community