Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 07781a2

Browse files
update
1 parent 11c73f6 commit 07781a2

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

‎7_Arrays_in_detail/Arrays.md‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
let months = ["January", "February", "March", "April"];
77

88
for (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");
3737
console.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

4343
names.splice(2, 2);
4444
console.log(names); // [ 'Samarth', 'Bob', 'David', 'Mark' ]
@@ -48,7 +48,7 @@ const noOneLikesSam = names.slice(1);
4848
console.log(noOneLikesSam); // [ 'Bob', 'David', 'Mark' ]
4949
```
5050

51-
#### forEach method
51+
#### forEach method
5252

5353
```js
5454
const numbers = [2, 4, 6, 8];
@@ -71,13 +71,13 @@ console.log(sum); // 20
7171

7272
```js
7373
const 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
8181
const 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
9696
const 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

102102
const employeesToReward = employeesData.filter(
103-
(employee) => employee.overtime >= 7
103+
(employee) => employee.overtime >= 7
104104
);
105105

106106
const 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
138138
const movies = ["Avengers", "Superman", "Batman"];
139139

140140
if (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"];
156156
names.sort();
157-
console.log(names); // [ 'Aditya', 'Divyanshi', 'Samarth', 'Shubham' ]
157+
console.log(names); // [ 'Aditya', 'Shruti', 'Samarth', 'Shubham' ]
158158

159159
const numbers = [4, 12, 8, 5, 1];
160160

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /