foeach in js
const avengers = ['thor', 'captain america', 'hulk'];
avengers.forEach((item, index)=>{
console.log(index, item)
})let colors = ['red', 'blue', 'green'];
// idx and sourceArr optional; sourceArr == colors
colors.forEach(function(color, idx, sourceArr) {
console.log(color, idx, sourceArr)
});
// Output:
// red 0 ['red', 'blue', 'green']
// blue 1 ['red', 'blue', 'green']
// green 2 ['red', 'blue', 'green']let marks = [12, 17, 14]
let sum = 0
marks.forEach(mark => {
sum += mark;
});
Also in JavaScript:
- how to check is the key of a localstorage is emopty
- jquery selector this and class
- redux connect
- react js documentation
- node express mongo boilerplate with jwt
- remove last element from array javascript
- javascript detectar la pagina
- typescript obejct replace propertyies
- javascript modal show
- difference between var let and const in javascript with example
- pyspark json multiline
- unordered list in react native
- react enzyme
- Image react native
- datatable dropdown toggle not working
- convert an image into Base64 string using JavaScript
- destruction in javascript
- ad data to js object
- ionic modal navbar not showing
- how to write img jsx
- js get file name from path
- react font awesome
- javascript loop object
- asking questions javascript in console