+ 5
how do i make simplest for loop in JavaScript
24 Answers
+ 16
Ana Djurica, the value in the element with index 0 is used to get access to another element with such index.
First, we have to look at what is in the inner square brackets, x[0]. The value of the element with index 0 is 2. Second, we put this value in the outer square brackets, x[2]. The value of the element with index 2 is 4.
We used the value of one element as index for another element, and my example is here:
https://code.sololearn.com/W77I87KIF1LI/?ref=app
+ 13
Ana Djurica, with examples it will be easier... I have to check something and then will post answer😊
+ 13
Ana Djurica, yes, there will be one array after concatenation, array b + array a😊
You are welcome😊
+ 11
Ana Djurica, you can do it this way:
var arr = [100,101,102];
for (var i = 0; i < arr.length; i++) {
document.write(arr[i] + "<br>");
}
or this:
var arr = [100,101,102];
for (var i = 0; i < arr.length; i++) {
alert(arr[i]);
}
+ 11
Ana Djurica, yes, I'm here😊 What question?
+ 10
Is this example suitable?😊
https://code.sololearn.com/WD2DQKgxfVws/?ref=app
+ 9
https://www.sololearn.com/learn/JavaScript/1140/
+ 9
alert(arr[1]);
+ 9
You are welcome, Ana Djurica😊
+ 8
You are welcome, happy learning and coding😊✨
+ 7
for (var a=0;a<5;a++){
alert(a);
}
Output:
0
1
2
3
4
+ 6
this is a question from challenges.
It goes like this:
What is the output of this code?
var a = [1, 3 , 4, 6, 8];
var b = [7, 3, 2, 9, 5];
var x = b.concat(a);
console.log(x[x[0]]);
whith that thar I consider b.concat(a) makes one array
+ 6
NezhnyjVampir O.K. understood, Thank you very much :) :) :)
+ 5
ok, but how do i make that instead of printing sequence of 012345.... it prints 0+1+2+3+4....
+ 5
and if I want to output only the second element in the array?
+ 5
nice.... I love codding. thank you @NezhnyjVampir .
+ 4
@NezhnyjVampir are you still here? I have one complicated question.
+ 4
what means x[x[0]] when I have only one array without subarrays?
+ 3
yes, but give me an example of code block i can make (without strings)
and where and how can i alert that, inside the brackets or out
+ 3
it works, thank you, hope i will soon be able to do more complicated things