top

Search

JavaScript Tutorial

The JavaScript for…in loop is used to iterate over properties of Objects. In JavaScript, Arrays are also Objects and each character in a string have an index. So, we can use them also to iterate over Arrays and Strings.//Object example const obj = { a: 1, b: 2, c: 3, d: 4 } for (const key in obj) { console.log( obj[key] ) }// Output: 1 2 3 4 //Array example const array = ['a', 'b', 'c', 'd']; for (const index in array) { console.log(array[index]) }// Output: a b c d //String example const string = 'Web Developer'; for (const index in string) {    console.log(string[index]) }//Output: W e b D e v e l o p e r
logo

JavaScript Tutorial

for…in loop

The JavaScript for…in loop is used to iterate over properties of Objects. In JavaScript, Arrays are also Objects and each character in a string have an index. So, we can use them also to iterate over Arrays and Strings.

//Object example
const obj = {
a: 1,
b: 2,
c: 3,
d: 4
}
for (const key in obj) {
console.log( obj[key] )
}

// Output: 

1 2 3 4
//Array example
const array = ['a', 'b', 'c', 'd'];
for (const index in array) {
console.log(array[index])
}

// Output:

a b c d
//String example
const string = 'Web Developer';
for (const index in string) {
   console.log(string[index])
}

//Output: 

W e b D e v e l o p e r

Leave a Reply

Your email address will not be published. Required fields are marked *

Comments

Aditya

The tutorial provides the more information JavaScript this provides the end to end information about JS and also they provides the more detailed concepts of loops, functions, objects, arrays this will use us to buld the effective web site. Thanks for the team good job.

Suggested Tutorials

Node JS Tutorial

Build various types of web applications,command-line application,etc.
Node JS Tutorial

Build various types of web applications,command-line application,etc....

Read More

Angular JS Tutorial

Introduction: Angular  (What is Angular?)Angular was formerly introduced by Google corporation in 2012 and was considered to be one of the most promising among JavaScript frameworks. It was written completely in JavaScript to separate an application’s logic from DOM manipulation, aiming at dynamic page updates. Angular introduced many powerful features enabling the developer to effortlessly create rich and single-page applications.Topics CoveredThis Angular tutorial will span over eight modules, each module covering numerous individual aspects that you need to gain complete information about Angular. This set of modules serves as an Angular tutorial for beginners along with experienced IT professionals.Here are the topics that will be covered in the Angular tutorial:Get started with Angular.Learn the basics of Angular.Know what Angular Directives.Get an idea of Component Inputs and Outputs of Angular.Know about Forms in Angular.About Services in Angular.Pipes in Angular.HTTP, Routing and Building in Angular.Who can benefit from this tutorial?This Angular tutorial will be helpful to IT professionals such as:Software Developers, Web Application Programmers and IT Professionals Software Architects and Testing Professionals Career aspirants in web development
Angular JS Tutorial

Introduction: Angular  (What is Angular?)Angular was formerly introdu...

Read More