74 lines
2.2 KiB
Markdown
74 lines
2.2 KiB
Markdown
---
|
|
id: 56533eb9ac21ba0edf2244cc
|
|
title: Accessing Nested Objects
|
|
challengeType: 1
|
|
guideUrl: 'https://spanish.freecodecamp.org/guide/certificates/accessing-nested-objects-in-json'
|
|
videoUrl: ''
|
|
localeTitle: Accediendo a objetos anidados
|
|
---
|
|
|
|
## Description
|
|
<section id="description"> Se puede acceder a las sub-propiedades de los objetos encadenando la notación de punto o corchete. Aquí hay un objeto anidado: <blockquote> var ourStorage = { <br> "escritorio": { <br> "cajón": "grapadora" <br> } <br> "gabinete": { <br> "cajón de arriba": { <br> "folder1": "un archivo", <br> "folder2": "secretos" <br> } <br> "cajón inferior": "soda" <br> } <br> }; <br> ourStorage.cabinet ["cajón superior"]. folder2; // "secretos" <br> ourStorage.desk.drawer; // "engrapadora" </blockquote></section>
|
|
|
|
## Instructions
|
|
<section id="instructions"> Acceda al objeto <code>myStorage</code> y asigne el contenido de la propiedad <code>glove box</code> a la variable <code>gloveBoxContents</code> . Utilice la notación de corchete para las propiedades con un espacio en su nombre. </section>
|
|
|
|
## Tests
|
|
<section id='tests'>
|
|
|
|
```yml
|
|
tests:
|
|
- text: <code>gloveBoxContents</code> debe ser igual a "mapas"
|
|
testString: 'assert(gloveBoxContents === "maps", "<code>gloveBoxContents</code> should equal "maps"");'
|
|
- text: Usa la notación de puntos y corchetes para acceder a <code>myStorage</code>
|
|
testString: 'assert(/=\s*myStorage\.car\.inside\[\s*("|")glove box\1\s*\]/g.test(code), "Use dot and bracket notation to access <code>myStorage</code>");'
|
|
|
|
```
|
|
|
|
</section>
|
|
|
|
## Challenge Seed
|
|
<section id='challengeSeed'>
|
|
|
|
<div id='js-seed'>
|
|
|
|
```js
|
|
// Setup
|
|
var myStorage = {
|
|
"car": {
|
|
"inside": {
|
|
"glove box": "maps",
|
|
"passenger seat": "crumbs"
|
|
},
|
|
"outside": {
|
|
"trunk": "jack"
|
|
}
|
|
}
|
|
};
|
|
|
|
var gloveBoxContents = undefined; // Change this line
|
|
|
|
```
|
|
|
|
</div>
|
|
|
|
|
|
### After Test
|
|
<div id='js-teardown'>
|
|
|
|
```js
|
|
console.info('after the test');
|
|
```
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
## Solution
|
|
<section id='solution'>
|
|
|
|
```js
|
|
// solution required
|
|
```
|
|
</section>
|