From the course: Learning ECMAScript 6+ (ES6+)
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Creating objects with the spread operator - JavaScript Tutorial
From the course: Learning ECMAScript 6+ (ES6+)
Creating objects with the spread operator
- [Instructor] In an earlier video, we looked at how you can use the spread operator with arrays. in this video, we'll take a closer look at how to use the spread operator with objects. So I'm going to create an object here called daytime. Inside of the daytime object, it's going to have keys for breakfast. We'll have some oatmeal. And then for lunch, we'll have peanut butter and jelly. Then we're going to go ahead and create a variable called nighttime. This is going to be equal to mac and cheese. So now what we want to do is we want to create sort of a menu. We want to create an object that contains both our breakfast, lunch, and nighttime items. So we could try this just by adding daytime and nighttime to our backpackingMeals. But if we console.log this, we see the same situation as with the array. We see some nesting going on where we don't want it to be. We want to take both the breakfast and the lunch items and put…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Enhancing object literals2m 8s
-
(Locked)
Creating objects with the spread operator1m 25s
-
(Locked)
Destructuring objects3m 2s
-
(Locked)
Iterating with the for/of loop2m 40s
-
(Locked)
Introducing classes2m 28s
-
(Locked)
Inheritance with JavaScript classes1m 39s
-
(Locked)
Getting and setting class values3m 35s
-
(Locked)
-
-
-