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

Creating objects with the spread operator - JavaScript Tutorial

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

Start my 1-month free trial

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…

Contents