From the course: Learning ECMAScript 6+ (ES6+)

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Writing maps

Writing maps - JavaScript Tutorial

From the course: Learning ECMAScript 6+ (ES6+)

Start my 1-month free trial

Writing maps

- [Instructor] The map object holds key value pairs. So what's the difference between a map and an object? In a map, any value, both objects and primitive values may be used either as a key or a value. So let's take a look at what these maps look like. Here on line one, I'm going to say, let course equals new map and we'll call that map constructor. Maps then have these methods on them called set so we can set values. So the key would be react and the value would be description ui, so that object. So then we can say course.set jest, and we'll give that one an object description as well. Jest is all about testing. So once I hit save on that, I want to console log it. Let's console log first, the course, then we'll console log course.react. Now, if I try to run this in the browser, we'll see the map being logged, but course.react, we're not seeing anything there. And that's because a map is different than an object, so…

Contents