66let months = [" January" , " February" , " March" , " April" ];
77
88for (let i = 0 ; i < months .length ; i++ ) {
9- console .log (months[i]);
9+ console .log (months[i]);
1010}
1111// January
1212// February
@@ -37,8 +37,8 @@ names.unshift("Samarth");
3737console .log (names); // [ 'Samarth', 'Bob', 'David', 'Mark' ]
3838
3939// Array Splice - It adds or removes values in any position of an array
40- names .splice (2 , 0 , " Divyanshi " , " Ayushi " );
41- console .log (names); // [ 'Samarth', 'Bob', 'Divyanshi ', 'Ayushi ', 'David', 'Mark' ]
40+ names .splice (2 , 0 , " Shruti " , " Rishi " );
41+ console .log (names); // [ 'Samarth', 'Bob', 'Shruti ', 'Rishi ', 'David', 'Mark' ]
4242
4343names .splice (2 , 2 );
4444console .log (names); // [ 'Samarth', 'Bob', 'David', 'Mark' ]
@@ -48,7 +48,7 @@ const noOneLikesSam = names.slice(1);
4848console .log (noOneLikesSam); // [ 'Bob', 'David', 'Mark' ]
4949```
5050
51- #### forEach method
51+ #### forEach method
5252
5353``` js
5454const numbers = [2 , 4 , 6 , 8 ];
@@ -71,13 +71,13 @@ console.log(sum); // 20
7171
7272``` js
7373const inventory = [
74- { price: 7 , name: " egg" },
75- { price: 10 , name: " lays" },
76- { price: 12 , name: " maggie" },
74+ { price: 7 , name: " egg" },
75+ { price: 10 , name: " lays" },
76+ { price: 12 , name: " maggie" },
7777];
7878
7979// Array Map
80- const prices = inventory .map ((item ) => console .log (item .price ));// displays only the prices
80+ const prices = inventory .map ((item ) => console .log (item .price ));// displays only the prices
8181const names = inventory .map ((item ) => console .log (item .name )); // diplays only the names
8282```
8383
@@ -94,21 +94,21 @@ console.log(negativeNumbers);
9494
9595// Another real life example
9696const employeesData = [
97- { name: " Shubham" , overtime: 5 },
98- { name: " Samarth" , overtime: 7 },
99- { name: " Seema" , overtime: 8 },
97+ { name: " Shubham" , overtime: 5 },
98+ { name: " Samarth" , overtime: 7 },
99+ { name: " Seema" , overtime: 8 },
100100];
101101
102102const employeesToReward = employeesData .filter (
103- (employee ) => employee .overtime >= 7
103+ (employee ) => employee .overtime >= 7
104104);
105105
106106const employeeNames = employeesToReward .map ((employee ) => employee .name );
107107
108- employeeNames .forEach ((user )=> {
109- console .log (` Congratulations, ${ user} ` ); // Congratulations, Samarth
110- // Congratulations, Seema
111- })
108+ employeeNames .forEach ((user )=> {
109+ console .log (` Congratulations, ${ user} ` ); // Congratulations, Samarth
110+ // Congratulations, Seema
111+ });
112112```
113113
114114#### Array Find
@@ -138,9 +138,9 @@ console.log(city); // New Delhi
138138const movies = [" Avengers" , " Superman" , " Batman" ];
139139
140140if (movies .includes (" Avengers" )) {
141- console .log (" The movie is available on prime" );// The movie is available on prime
141+ console .log (" The movie is available on prime" );// The movie is available on prime
142142} else {
143- console .log (" The movie is not available on prime." );
143+ console .log (" The movie is not available on prime." );
144144}
145145
146146// Note Includes method is case sensitive
@@ -152,9 +152,9 @@ if (movies.includes("Avengers")) {
152152// Array sort => Alphabetically,
153153// doesn't sort numbers
154154// This sort method mutates the original array
155- const names = [" Shubham" , " Aditya" , " Divyanshi " , " Samarth" ];
155+ const names = [" Shubham" , " Aditya" , " Shruti " , " Samarth" ];
156156names .sort ();
157- console .log (names); // [ 'Aditya', 'Divyanshi ', 'Samarth', 'Shubham' ]
157+ console .log (names); // [ 'Aditya', 'Shruti ', 'Samarth', 'Shubham' ]
158158
159159const numbers = [4 , 12 , 8 , 5 , 1 ];
160160
0 commit comments