I try to reverse an array but without the reverse function.
Like you see I try to decrement the length of the array num=(tab.length-i)-1, so it works. But when I try to add tab[i]=tab[num], it works but the value push inside tab[i] is random [ 10, 9, 8, 7, 6, 6, 7, 8, 9, 10 ].
Do you have any idea why ?
const tab=[1,2,3,4,5,6,7,8,9,10]
let num=0
for(let i=0;i<tab.length;i++){
num=(tab.length-i)-1
console.log(num)
tab[i]=tab[num]
}
reverse? You could clone the array first if you want to avoid changing the original array. E.g.tab.slice(0).reverse().