+ 5

how do i make simplest for loop in JavaScript

7th Jun 2018, 7:03 PM
it371
it371 - avatar
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
17th Jun 2018, 6:37 PM
NezhnyjVampir
+ 13
Ana Djurica, with examples it will be easier... I have to check something and then will post answer😊
17th Jun 2018, 6:02 PM
NezhnyjVampir
+ 13
Ana Djurica, yes, there will be one array after concatenation, array b + array a😊 You are welcome😊
17th Jun 2018, 6:59 PM
NezhnyjVampir
+ 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]); }
8th Jun 2018, 1:28 PM
NezhnyjVampir
+ 11
Ana Djurica, yes, I'm here😊 What question?
17th Jun 2018, 5:39 PM
NezhnyjVampir
+ 10
7th Jun 2018, 7:26 PM
NezhnyjVampir
+ 9
https://www.sololearn.com/learn/JavaScript/1140/
7th Jun 2018, 7:05 PM
NezhnyjVampir
+ 9
alert(arr[1]);
8th Jun 2018, 1:49 PM
NezhnyjVampir
+ 9
You are welcome, Ana Djurica😊
8th Jun 2018, 2:33 PM
NezhnyjVampir
+ 8
You are welcome, happy learning and coding😊✨
7th Jun 2018, 7:50 PM
NezhnyjVampir
+ 7
for (var a=0;a<5;a++){ alert(a); } Output: 0 1 2 3 4
8th Jun 2018, 1:32 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 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
17th Jun 2018, 6:47 PM
it371
it371 - avatar
+ 6
NezhnyjVampir O.K. understood, Thank you very much :) :) :)
17th Jun 2018, 6:58 PM
it371
it371 - avatar
+ 5
ok, but how do i make that instead of printing sequence of 012345.... it prints 0+1+2+3+4....
8th Jun 2018, 4:58 AM
it371
it371 - avatar
+ 5
and if I want to output only the second element in the array?
8th Jun 2018, 1:44 PM
it371
it371 - avatar
+ 5
nice.... I love codding. thank you @NezhnyjVampir .
8th Jun 2018, 2:16 PM
it371
it371 - avatar
+ 4
@NezhnyjVampir are you still here? I have one complicated question.
17th Jun 2018, 5:38 PM
it371
it371 - avatar
+ 4
what means x[x[0]] when I have only one array without subarrays?
17th Jun 2018, 5:46 PM
it371
it371 - avatar
+ 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
7th Jun 2018, 7:20 PM
it371
it371 - avatar
+ 3
it works, thank you, hope i will soon be able to do more complicated things
7th Jun 2018, 7:48 PM
it371
it371 - avatar