Skip to content

Commit ca24f7c

Browse files
committed
Array - includes()
1 parent 8877ae3 commit ca24f7c

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

app.js

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,10 @@
1-
// String includes() - checks if a string contains another string.
1+
// Array includes() - checks if a string contains another string.
2+
// Array includes - checks if the item is an array
23

3-
console.log("=== Case Sensitive ===");
4-
const product = {
5-
title: "Leather Chair",
6-
};
7-
console.log(product.title.includes("le"));
4+
const groceries = ["milk", "apple", "banana", "carrot"];
85

9-
console.log("=== 2nd Argument ===");
10-
const firstName = "peter";
11-
const result = firstName.includes("pe", 0);
12-
console.log(result);
6+
let item = "lemon";
7+
item = "milk";
138

14-
/* Products */
15-
const products = [
16-
{ title: "Modern Poster" },
17-
{ title: "Bar Stool" },
18-
{ title: "Armchair" },
19-
{ title: "Leather Chair" },
20-
];
21-
22-
const searchTitle = "a";
23-
24-
const filteredProducts = products.filter((item) =>
25-
item.title.toLowerCase().includes(searchTitle)
26-
);
27-
console.log(filteredProducts);
9+
const isItemIncluded = groceries.includes(item, 1);
10+
console.log(isItemIncluded);

0 commit comments

Comments
 (0)