Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele The `includes` Method | Exploring Arrays
Introduction to JavaScript
course content

Kurssisisältö

Introduction to JavaScript

Introduction to JavaScript

1. Getting Started
3. Conditional Statements
4. Mastering Functions
5. Exploring Arrays
6. Discovering Loops

book
The `includes` Method

The includes method can be used to quickly determine of a specific element exists in the array or not.

Following is the general syntax of the includes method:

python

The includes method returns a boolean (true or false) value based on whether or not the element exists in the array.

  • Returnstrue if the element is found;

  • Returnsfalse if the element is not found.

1234
let itemsInStock = ["Laptop", "Phone", "Tablet", "Charger"]; console.log(itemsInStock.includes("Phone")); console.log(itemsInStock.includes("Headphones"));
copy
Note
Note

The includes method performs a strict comparison (===), meaning it checks for exact matches, including case sensitivity. For example, itemsInStock.includes("phone") would return false because "phone" (lowercase) is not the same as "Phone" (uppercase "P").

1. What will be the output of the following code?

2. Which of the following statements is true about the includes method?

question mark

What will be the output of the following code?

Select the correct answer

question mark

Which of the following statements is true about the includes method?

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 5. Luku 10

Kysy tekoälyä

expand
ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

course content

Kurssisisältö

Introduction to JavaScript

Introduction to JavaScript

1. Getting Started
3. Conditional Statements
4. Mastering Functions
5. Exploring Arrays
6. Discovering Loops

book
The `includes` Method

The includes method can be used to quickly determine of a specific element exists in the array or not.

Following is the general syntax of the includes method:

python

The includes method returns a boolean (true or false) value based on whether or not the element exists in the array.

  • Returnstrue if the element is found;

  • Returnsfalse if the element is not found.

1234
let itemsInStock = ["Laptop", "Phone", "Tablet", "Charger"]; console.log(itemsInStock.includes("Phone")); console.log(itemsInStock.includes("Headphones"));
copy
Note
Note

The includes method performs a strict comparison (===), meaning it checks for exact matches, including case sensitivity. For example, itemsInStock.includes("phone") would return false because "phone" (lowercase) is not the same as "Phone" (uppercase "P").

1. What will be the output of the following code?

2. Which of the following statements is true about the includes method?

question mark

What will be the output of the following code?

Select the correct answer

question mark

Which of the following statements is true about the includes method?

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 5. Luku 10
Pahoittelemme, että jotain meni pieleen. Mitä tapahtui?
some-alt