0

exercice of array

Hello world somebody could explain me why the result of this exercice is 6 ? thank you https://www.sololearn.com/Play/JavaScript What is the output of this code? var arr = new Array(3, 6, 8); document.write(arr[1]);

19th Jul 2017, 2:12 AM
Michael Tuninetti
Michael Tuninetti - avatar
11 Respuestas
+ 4
.... -_- stack up stack up array pattern : [3,6,8] stack pattern _______ 8 floor 2 6 floor 1 3 floor 0 _______ Get arr[1] value = Get the value that Stack at floor 1 Get it?
19th Jul 2017, 7:47 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 1
new Array() same thing to [ ] so new Array(3,6,8) equilvalent to [3,6,8] (just try to think that array is object from "new Array()" ) __________________________________ Ok now more with this function "new Array()" you can define empty array{ var a = new Array(4);//If you paste only one argument and that argument is number alert(a.length); } what is it for then?: { var a = new Array(4); for(i=0;i<a.length;i++){ //some code here } }
19th Jul 2017, 2:16 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 1
:/... Then Do you know what stack is?
19th Jul 2017, 2:40 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 1
the answer is 6
9th Nov 2021, 3:57 AM
Nabila Muftia Ma'ruf Kartono
Nabila Muftia Ma'ruf Kartono - avatar
0
thank you guys but sorry i still didnt understand why the result is 6 ? https://www.sololearn.com/Play/JavaScript What is the output of this code? var arr = new Array(3, 6, 8); document.write(arr[1]);
19th Jul 2017, 2:38 AM
Michael Tuninetti
Michael Tuninetti - avatar
0
:/... Then Do you know what stack is? = I think it is a bracket in comment isnt?
19th Jul 2017, 6:38 AM
Michael Tuninetti
Michael Tuninetti - avatar
0
Fill in the blanks to output only the even numbers in the array. var arr = arrayOf(1, 2, 5, 6, 2, 8, 9) for(x in arr) { if (x % 2 != 0) { } println( ) } any help..?
20th Mar 2021, 10:46 AM
Mostafa Alafif
Mostafa Alafif - avatar
0
use continue after if(x%2!=0) { continue } println(x)
14th Oct 2021, 12:16 PM
Sangeeta J.Pandey
0
fun main(args: Array<String>) { val arr = arrayOf(42, 3, 10, 4, 6, 1) val res = arr.filter({ it > 5 }) println(res) }
13th Jan 2023, 12:18 PM
Wondifraw Seifu
Wondifraw Seifu - avatar
- 1
The counting in array starts from 0 1 2 3 .... So are[1] would be 6
19th Jul 2017, 2:21 AM
G.S.N.V. Suraj
G.S.N.V. Suraj - avatar
- 1
thank you so much i get it !! great your explanation ... -_- stack up stack up array pattern : [3,6,8] stack pattern _______ 8 floor 2 6 floor 1 3 floor 0 _______ Get arr[1] value = Get that Stack at floor 1 Get it?
19th Jul 2017, 10:14 AM
Michael Tuninetti
Michael Tuninetti - avatar