1+ //array
2+ //PART 1
3+
4+ const myArr = [ 0 , 1 , 2 , 3 , 4 , 5 ]
5+
6+ const myHeroes = [ "shaktiman" , "naagraj" ]
7+
8+ const myArr2 = new Array ( 1 , 2 , 3 , 4 )
9+ //console.log(myArr[1]);
10+
11+ // array methods
12+
13+ //myArr.push(6)
14+ //myArr.pop()
15+
16+ //myArr.unshift(9) //adds 9 in the beginning
17+ //myArr.shift() //removes first element
18+
19+ //console.log(myArr.includes(9));
20+ //console.log(myArr.indexOf(3));
21+
22+ const newArr = myArr . join ( ) //convert to string
23+
24+ //console.log(myArr);
25+ //console.log(typeof newArr);
26+
27+ //slice, splice
28+
29+ //console.log("A ", myArr);
30+
31+ const myn1 = myArr . slice ( 1 , 3 ) //will show arr including index 1 and 2 only
32+
33+ //console.log(myn1);
34+ //console.log("B ", myArr); //array remains saim as original
35+
36+
37+ const myn2 = myArr . splice ( 1 , 3 ) //will show arr with element of index 3 as well
38+ //console.log("C ", myArr); //elements spliced will be removed
39+ //console.log(myn2);
40+
41+
42+ //PART 2
43+
44+ const marvel_heros = [ "thor" , "Ironman" , "Spiderman" ]
45+ const dc_heroes = [ "superman" , "flash" , "batman" ]
46+
47+ // marvel_heros.push(dc_heros)
48+
49+ // console.log(marvel_heros);
50+ // console.log(marvel_heros[3][1]);
51+
52+ // const allHeros = marvel_heros.concat(dc_heros)
53+ // console.log(allHeros);
54+
55+ const all_new_heros = [ ...marvel_heros , ...dc_heros ]
56+
57+ // console.log(all_new_heros);
58+
59+ const another_array = [ 1 , 2 , 3 , [ 4 , 5 , 6 ] , 7 , [ 6 , 7 , [ 4 , 5 ] ] ]
60+
61+ const real_another_array = another_array . flat ( Infinity )
62+ console . log ( real_another_array ) ;
63+
64+ console . log ( Array . isArray ( "naini" ) )
65+ console . log ( Array . from ( "naini" ) )
66+ console . log ( Array . from ( { name : "naini" } ) ) //returns empty array, need to mention keys or values
67+
68+ let score1 = 100
69+ let score2 = 200
70+ let score3 = 300
71+
72+ console . log ( Array . of ( score1 , score2 , score3 ) ) ;
0 commit comments