Javascript Best Practices - Use For In Loops

For loops can be shortened and cleaned. Let’s see an example:

Long form:


const friends = ['amar', 'akbar', 'anthony'];
for (let i = 0; i < friends.length; i++){
 console.log(friends[i]);
}

Short / clean form:


const friends = ['amar', 'akbar', 'anthony'];
for (const friend in friends){
 console.log(friend);
}

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for…in



Nordible is a digital solutions provider helping organizations achieve their digital goals.

We develop and measure digital solutions, implement impactful brand promotion and SEO strategies and develop software driven by rigorous testing that help your business succeed online and beyond.

You can contact us at info@nordible.com for business inquiries.

Follow us: