Previous Lecture Complete and continue  

  ES5 - Object.keys

Video Summary:

Object.keys has been a part of Javascript for quite a while but it has become popularized along with the functional movement in the Javascript community.

What it does:

Object.keys is a function on the Object constructor that takes in an object and outputs that objects keys into an array.

Why it's valuable:

Array's have far more useful helper methods and by using Object.keys instead of the traditional for (var key in obj) syntax it is much easier to chain transformational methods to the object in the same way we would do with an array.

14 comments
vikin
This is good!
anteriovieira
Awesome!
Victor
Array's instead of Arrays in first word of last paragraph.
Jonathan Creasman
8 more days!
QianYong
Got
juliomatcom
I was expecting a more functional example like:
// ...
var keys = Object.keys(obj);
var incrementKeyWithObj = function (objValues) {
return function (key) {
return objValues[key] * 2;
}
}
var timesTwo = keys.map(incrementKeyWithObj(obj));
Phillip Mwaniki Nzuli
Same here
John Smith
what code editor are you using?
Nick L
It's babeljs.io , then hit the try it out tab,
Derek H
As this is an intro class, I think all semicolons should be shown even if they are optional ie:
var obj = {...}; console.log(...);
Moshood Temitope
Lets move on!
Jogchum Koerts
Maybe it's good to mention that Object.keys only returns the property keys from the object itself, just like you would check with Object.prototype.hasOwnProperty() when using the for .. in loop on an object.
Daniel Uhl
What editor are you using in this video?
VICTOR BASURTO
Great... I like it