+ 3
var arr=[1,4,6,4,2]; for(var i=0; i<3; i++){ arr[i]=arr[i]+arr[i+2]; } document.write(arr[3]);
What is the output of this code? var arr=[1,4,6,4,2]; for(var i=0; i<3; i++){ arr[i]=arr[i]+arr[i+2]; } document.write(arr[0]); https://code.sololearn.com/WggijYpSg59h/?ref=app
4 Antworten
+ 4
4
+ 6
What is your question?
Run the code to see the output.
+ 3
Lisa Can someone explain to me how to get 4 in the output....?🙄
+ 2
/*
Print each step out and compare with the result:
*/
let arr=[1,4,6,4,2];
for(let i=0; i<3; i++){
console.log(`${i}: ${arr[i]}+${arr[i+2]}`); // print each iteration
arr[i]=arr[i]+arr[i+2];
}
console.log(arr); // print result