0%

js array loop

clientX vs pageX

1
2
3
4
5
6
let i = 0;

while (i < scores.length) {
console.log(scores[i]);
i++;
}
1
2
3
4
5
6
let i = 0;

do {
console.log(scores[i]);
i++;
} while (i < scores.length);
1
2
3
for (let i = 0; i < scores.length; i++) {
console.log(scores[i]);
}
1
2
3
for (i in scores) {
console.log(scores[i]);
}
1
2
3
for (score of scores) {
console.log(score);
}

forEach

map

reduce

reduceRight

flatMap

filter

every

some

indexOf

lastIndexOf

find

findIndex

keys

entries

includes

Spread …

via https://www.w3schools.com/js/js_array_iteration.asp

via https://www.w3schools.com/jsref/jsref_obj_array.asp

at

1
2
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let fruit = fruits.at(-2);

array.slice(start, end)

The slice() method does not change the original array.

array.splice(index, howmany, item1, ….., itemX)

The splice() method overwrites the original array.

copyWithin

array.copyWithin(target, start, end)