0

help me out with arrays please

I'm telling the code to remove the following array (1,2) which should be Mike and pauljerq and I expected to have jones remaining, surprisingly I'm getting "Mike" on the output, can someone please tell me why? var users = ["Jones" , "mike", "pauljerq"]; var slice= users.slice(1,2); document.write(slice)

9th Nov 2019, 2:07 AM
Glory222
Glory222 - avatar
3 Answers
+ 6
slice() selects the elements whose index is passed to it. And when you write slice(1,2) always remember that index 1 is only accessed and 2 is not included. So to print Jones you should write slice(0,1). I guess I am right. So for eg if you say slice(5,10) then you can access index 5,6,7,8,9 but not 10.
9th Nov 2019, 2:35 AM
Avinesh
Avinesh - avatar
+ 2
Glory222 you're welcome
9th Nov 2019, 3:15 AM
Avinesh
Avinesh - avatar
0
Thanks
9th Nov 2019, 3:13 AM
Glory222
Glory222 - avatar