2018-10-08 13:34:43 -04:00

2.4 KiB

id, title, localeTitle, challengeType, guideUrl
id title localeTitle challengeType guideUrl
56533eb9ac21ba0edf2244cc Accessing Nested Objects Accediendo a objetos anidados 1 https://spanish.freecodecamp.org/guide/certificates/accessing-nested-objects-in-json

Description

Se puede acceder a las sub-propiedades de los objetos encadenando la notación de punto o corchete. Aquí hay un objeto anidado:
var ourStorage = {
  "desk": {
    "drawer": "stapler"
  },
  "cabinet": {
    "top drawer": {
      "folder1": "a file",
      "folder2": "secrets"
    },
    "bottom drawer": "soda"
  }
};
ourStorage.cabinet["top drawer"].folder2; // "secrets"
ourStorage.desk.drawer; // "stapler"

Instructions

Acceda al objeto myStorage y asigne el contenido de la propiedad de la glove box a la variable gloveBoxContents . Utilice la notación de corchete para las propiedades con un espacio en su nombre.

Tests

tests:
  - text: <code>gloveBoxContents</code> debe ser igual a &quot;mapas&quot;
    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>");'

Challenge Seed

// Setup
var myStorage = {
  "car": {
    "inside": {
      "glove box": "maps",
      "passenger seat": "crumbs"
     },
    "outside": {
      "trunk": "jack"
    }
  }
};

var gloveBoxContents = undefined; // Change this line

After Test

console.info('after the test');

Solution

var myStorage = {
  "car":{
    "inside":{
      "glove box":"maps",
      "passenger seat":"crumbs"
    },
    "outside":{
      "trunk":"jack"
    }
  }
};
var gloveBoxContents = myStorage.car.inside["glove box"];