When I only use console.log() inside the forEach method it logs all the Array elements, but when I use the .push(array.pop()) inside it, it stops at some of the elements?
const sentence = ['sense.','make', 'all', 'will', 'This'];
function reverseArray(array) {
debugger;
let newArray = [];
array.forEach((arr) => {
newArray.push(array.pop())
console.log(arr)
})
return newArray;
}
console.log(reverseArray(sentence))
// RESULT [
// "This",
// "will",
// "all"
// ]
But here it works
const sentence = ['sense.','make', 'all', 'will', 'This'];
function reverseArray(array) {
debugger;
array.forEach((arr) => {
console.log(arr)
})
}
reverseArray(sentence)
// Now it works
// RESULT
// sense.
// VM94:7 make
// VM94:7 all
// VM94:7 will
// VM94:7 This