For of loop

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 172:- For of loop

The for...of loop is a newer way of iterating through arrays or other iterable objects in JavaScript. It was introduced in ES6 (ECMAScript 2015).

The for...of loop works by iterating over the values of an iterable object, rather than iterating over its indices like the traditional for loop or the forEach() method. Here's an example of how to use a for...of loop to iterate through an array:

cCopy code

const array = [1, 2, 3, 4, 5]; for (const element of array) {  console.log(element); }

In the above example, the for...of loop is used to iterate over each element of the array, and the value of each element is printed to the console using console.log(). The loop variable element is declared with the const keyword, which means that it cannot be reassigned within the loop.

The for...of loop can also be used with other iterable objects, such as strings and maps. Here's an example of how to use a for...of loop to iterate through the characters of a string:

cCopy code

const string = 'Hello, world!'; for (const char of string) {  console.log(char); }

In this example, the for...of loop is used to iterate over each character in the string, and the value of each character is printed to the console using console.log().

20. Mini Project Using JavaScript

Comments: 2

profile
@niteshguptav63
17-Nov-2024, 01:39 PM

I am not able to access videos from second class and further. I have already completed first class

profile
@niteshguptav63
16-Nov-2024, 10:56 AM

When will I get my course?

profile
@admin79
17-Nov-2024, 01:29 PM

Now, Your query was resolved.

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?