3 ways to loop over Object properties with Vanilla JavaScript

It happens a lot that you need to loop over an Array with JavaScript Objects! But sometimes you just donโ€™t know what kind of properties that Object has. Lucky we are that JavaScript offers a few ways of looping over JavaScript Object properties.

I wanted to share 3 of them with you. So hopefully this will help you in the right direction.

The Object to loop over

First, we need an example object to loop over. So I put some of my experience in it ๐Ÿ˜‰ (hahaha)! Keep the fun in it!

let experienceObject = { name: 'Raymon', title: 'Lead Frontend/JavaScript Developer', yearsExperience: 8, projects: [ { name: 'ANWB', title: 'Senior JavaScript Developer', techniques: ['Angular', 'ES6', 'Vanilla JavaScript', 'Less', 'CSS'] }, { name: 'NATO', title: 'Lead JavaScript Developer', techniques: ['Angular 2', 'AngularJS', 'ES6', 'Vanilla JavaScript', 'Web Sockets', 'D3'] }, { name: 'Rabobank', title: 'Senior Frontend Developer', techniques: ['Vanilla JavaScript', 'CSS', 'Responsive Webdesign'] } ] } Read more

I Love the JavaScript shorthand of If-else statement ๐Ÿ˜ƒ

So there it is! It is a long time ago that I put online a new blog post! Did a lot of other stuff then Web Development. But this time I want to share a small nice trick in JavaScript!

Yes, I love the JavaScript shorthand of the if-else statement. (For the record, the let variable is an ES6ย type variable.) Check the super simple example below.

let aVar = 'A';
let conditionalVariable = aVar === 'A' ? true : false;

This example is super simple. I use this most of the times when the value of a variable needs to be based on the other variable.

In the early days of me writing an if-else statement in JavaScript was more like this:

var aVar = 'A'; if(aVar === 'A') { var conditionalVariable = true; } else { var conditionalVariable = false; } Read more