JavaScript – How to get an array of object keys

The goal

Given a Javascript object you want to get an array of its keys. For example, given the following object:

var myObj = {
    firstName: "John",
    lastName: "Doe",
    phoneNumber: "+1 234 567 890",
    emailAddress: "john.doe@example.com"
}

You want to get its keys into an array:

["firstName", "lastName", "phoneNumber", "emailAddress"]

The problem

This can easily be achieved using Object.keys() like this:

var myObj = {
    firstName: "John",
    lastName: "Doe",
    phoneNumber: "+1 234 567 890",
    emailAddress: "john.doe@example.com"
};

var myKeys = Object.keys(myObj);
console.log(myKeys);

The code above works great in Chrome:

But throws an ‘Object doesn’t support property or method keys’ error in IE 8 or earlier:

A solution

This is a possible solution which works in both browsers:

var myObj = {
    firstName: "John",
    lastName: "Doe",
    phoneNumber: "+1 234 567 890",
    emailAddress: "john.doe@example.com"
};

var objectKeys = Object.keys || function(obj) {
    var res = [];
    for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
    }
    return res;
};

myKeys = objectKeys(myObj);
console.log(myKeys);

Seems to work okay in IE 8 and earlier:

Portrait of a Physical Therapist: Anca Tudor

[Updated 2019/02/09]

From treatment to personal development

Kinetotherapy Exercises for Kids
Anca at Activelife Romania teaching school kids on how to exercise correctly and grow up healthy
This is not your common article. I’m going to tell you my story of how physical therapy had a strong influence on my body, mind and spirit. I owe most of my transition to one person alone.

I met Anca Tudor by chance in 2014 when she was leading the kinetotherapy program at the company I was working for.

One evening, as I was heading home, I ran into her while she was talking to some of my colleagues who had already been enrolled in the program. She asked me to join the program. I don’t remember exactly the reasons she gave me for why I should, and I don’t remember why I decided to do it. It’s most probably all in the way she asked. In the end I decided to give it a go. I had been experiencing some back pain lately and I figured I had nothing to lose.

The big day comes knocking in
Anca Tudor Premium Welleness Advisor - Activelive
Anca Tudor Premium Wellness Advisor – Activelive.ro

Next Monday, 17:30, I was there all dressed up for kinetotherapy. And by that I mean I was wearing my long sweat pants, a loose t-shirt and – sneakers. I have to admit I was a little self-conscientious about my shape, me being overweight and all that. Which explains my choice for long sweat pants during a hot summer day in a room without air conditioning where I knew I was going to perform some sort of physical exercise.

The others were already there doing their thing, warming up. They had been going to the therapy sessions for a while now and they knew the routine. Anca greeted me with a big smile on her face. 

Continue reading “Portrait of a Physical Therapist: Anca Tudor”

Turbomecanica is going down Lessons on life from a demolition site

They are bringing it down. After forty years of existence it’s going to be replaced by apartment buildings: Mediafax article.

I have been passing by it every day for the past ten years. I cannot say I have a special connection with it. It’s just an old factory on my way to the office. And sometimes it’s the reason for the burnt kerosene smell and loud jet engine noise I can feel while at the office.

Some time ago I was on my way to work and I saw the excavators chewing away at the last remaining Turbomecanica buildings. They were tearing it down one small piece at a time.

As I don’t see anything remotely similar to this everyday, I stopped, I took my phone out and snapped some photos.

 
Almost done...
Almost done…

Pretty impressive, right?

What happened next was a little bit strange. Continue readingTurbomecanica is going down Lessons on life from a demolition site

Outlook’s Delivery Receipt and Read Receipt Features

Today I want to talk about Outlook’s read receipt and delivery receipt features, how they work, how to disable them and why you should.

I’ve been using Outlook, Microsoft’s email client, almost every day since 2005. Back then it was Outlook 2003, today it’s Outlook 2007. I know what you are going to say: Outlook 2013 has been out for a while now and you are still using the 2007 version?

What can I say? This is the speed at which things move in big companies. Upgrades come at a very slow pace and sometimes, some versions get skipped altogether. For example the company I work for went from Windows XP directly to Windows 7 skipping Vista.

The two features I want to address, read receipt and delivery receipt, have been part of Outlook since at least Outlook 2003. Let me briefly explain what each one of them does:

  • The delivery receipt option, if enabled, notifies the sender of an email message that his or her email has been delivered to the recipient’s mail box.
  • The read receipt option, if enabled, notifies the sender of an email message that his or her email has been opened by the message recipient.

Let’s take a closer look at how Outlook achieves these two features. Continue reading “Outlook’s Delivery Receipt and Read Receipt Features”