However, when dynamically setting values in a nested object (when you don't know exactly what the name of the key is going to be), you have to use the bracket notation. Using the dot notation is a great way to access values in nested objects. Copy and paste the previous example into a snippet or make up your own example to practice! Accessing and Setting values in nested objects If you can't get to a point where you can easily manipulate nested data structures, you'll have a very difficult time integrating any kind of outside data into the applications you'll be building later on. It is imperative that you understand how to access data in these nested data structures. So you may be thinking, am I really going to be working with data like this? Seriously? The answer is a strong YES! Very commonly, when you receive large amounts of data from third parties, you will be given it in a format that includes nested objects and/or arrays. Objects within Objectsīelow is a simple example of creating an object that has a key and the value for that key is another object:įavoriteHobbies: ,įavoriteBasketballTeam: " New York Knicks ",ĬitiesLivedIn: What, then, is a nested data structure? It just means one data structure inside of another! Let's start with a simple example. As we'll see in this unit, even with just these two data structures, we can get pretty far in terms of storing and accessing complex data. We've already seen how to use both of these structures to organize data. Do you just need to read the data, or do you need to update it? How large is your set of data, and how quickly do you need to find things in it? Questions like these greatly influence what type of data structure you should be using.įor now, though, we'll keep things limited to Objects and Arrays. In computer science, there are a multitude of different data structures (as you'll see!), because the most efficient way to store data depends on how you intend to use the data. These days I avoid framework-oriented posts since Node.js has taken over the world and JavaScript toolkits come and go. So what do we mean by data structure? In some sense, a data structure is just that: a way of structuring data. Back when JavaScript frameworks like MooTools and jQuery ruled the land we all wrote tutorials which were framed more toward the given framework instead of vanilla JavaScript. Add and remove data inside of a complex data structure.Access and iterate over data in a nested data structure.Create nested data structures using objects.By the end of this chapter, you should be able to:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |