For example, If I have an array a=[1,2,3,4,5,6,7,8] and b=[]. On every click event, I am passing a number as a parameter. I need to push the array a[] to array b[] from the next element. For the first click, I am passing 3 as parameter. Now array b[] will be copied from a[0] to a[2] which gives me array b=[1,2,3].
When I click second time with passing 2 as parameter, Now array b[] will be copied from a[3] to a[4] which gives me array b=[1,2,3,4,5].
Desired result: click(3) = b[1,2,3] click(2) = b[1,2,3,4,5]
Instead I am getting this click(3) = b[1,2,3] click(2) = b[1,2]
a=[1,2,3,4,5,6,7,8];
b = [];
click(e){
for(let i=0; i<=e; i++){
b.push(a[i])
}
How to do this? Any thoughts!! Thanks in advance.