As part of my learning journey, I successfully extracted every second element from an array using a for loop:
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
function filterEverySecond(arr) {
let everySecondEl = [];
for (let i = 0; i < arr.length; i += 2) {
everySecondEl.push(arr[i]);
}
return everySecondEl;
}
console.log({
numbers,
result: filterEverySecond(numbers)
});
Now, I am looking to achieve the same outcome without using a for loop, but instead by utilizing array methods such as forEach, filter, map, or reduce. Would appreciate some recommendations on which method would be most suitable for this scenario.