0

Can get this one

Var arr = [1,2,3]; var str = “abc”; Var x = 1 Do { Arr[x] = str[arr[x]]; <- explain this pls X++; } While (x<arr.length -1); <- and this: it give us 1 loop Alert (arr); Output is 1,c,3

2nd Mar 2022, 1:23 AM
Evgeny Sergeev
Evgeny Sergeev - avatar
1 Answer
+ 3
arr[1] = str[arr[1]] = str[2] = c It means second element of the array arr is assigned as c. while(2<3-1) Since condition evaluates false, loop stops running and print the updated arr. [1,c,3]
2nd Mar 2022, 2:40 AM
Simba
Simba - avatar