Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

array iteration

let arr = ['js', 'python', 'c++', 'dart']

// no 1
for (item of arr) {
	console.log(item);
}

// no 2
for (var item = 0; item < arr.length; item++) {
	console.log(arr[i]);
}

// no 3
arr.forEach(item=>{
	console.log(item);
})

// no 4
arr.map(item=>{
	console.log(item);
})

// no 5
var item = 0;
while (item < arr.length) {
	console.log(arr[item]);
  	item++;
}





Comment

iterate array

    for (let value of array) {
      sum+=value;
    }
Comment

iterate array

for (let [key,val] of array.entries()) {
  console.log([key,val]);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: js fibonacci sequence 
Javascript :: fahrenheit to celsius in javascript 
Javascript :: send csrf token ajax laravel 
Javascript :: js add array to array 
Javascript :: package.json in node js 
Javascript :: http node 
Javascript :: promise.race polyfill 
Javascript :: how to change background image dynamically in react 
Javascript :: return a date time object in yyyy-mm-dd hr:min:sec 
Javascript :: Handle click outside a component in react with hooks 
Javascript :: javascript get black or white text base on color 
Javascript :: fetching data with react 
Javascript :: javascript detect tab leave 
Javascript :: format javascript date 
Javascript :: Auto open browser when run dev nextjs 
Javascript :: ping ip address using javascript 
Javascript :: open folder node js 
Javascript :: insert element in specific index javascript 
Javascript :: javascript fromEntries 
Javascript :: Print array of objects js 
Javascript :: visual studio code create react component shortcut 
Javascript :: datepicker select date programmatically bootstrap 
Javascript :: how to reverse a string in JavaScript using reduce function 
Javascript :: largest and smallest number in an array 1-100 javascript 
Javascript :: reverse javascript 
Javascript :: ternary operator javascript 
Javascript :: react usecontext 
Javascript :: Limit text to specified number of words using Javascript 
Javascript :: react router dom change default path 
Javascript :: generators in javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =