[]
). Si la propiedad del objeto al que intenta acceder tiene un espacio en su nombre, deberá utilizar la notación de corchetes. Sin embargo, aún puede usar la notación de corchete en las propiedades del objeto sin espacios. Aquí hay una muestra del uso de la notación de corchetes para leer la propiedad de un objeto: var myObj = {Tenga en cuenta que los nombres de propiedades con espacios en ellos deben estar entre comillas (simple o doble).
"Nombre del espacio": "Kirk",
"Más espacio": "Spock",
"NoSpace": "USS Enterprise"
};
myObj ["Nombre del espacio"]; // Kirk
myObj ['Más espacio']; // Spock
myObj ["NoSpace"]; // USS Enterprise
"an entree"
y "the drink"
de testObj
utilizando la notación de corchetes y asignarlos a entreeValue
y drinkValue
respectivamente. entreeValue
debe ser una cadena
testString: 'assert(typeof entreeValue === "string" , "entreeValue
should be a string");'
- text: El valor de entreeValue
debe ser "hamburger"
testString: 'assert(entreeValue === "hamburger" , "The value of entreeValue
should be "hamburger"
");'
- text: drinkValue
debe ser una cadena
testString: 'assert(typeof drinkValue === "string" , "drinkValue
should be a string");'
- text: El valor de drinkValue
debe ser "water"
testString: 'assert(drinkValue === "water" , "The value of drinkValue
should be "water"
");'
- text: Usted debe usar la notación de soporte dos veces
testString: 'assert(code.match(/testObj\s*?\[("|")[^""]+\1\]/g).length > 1, "You should use bracket notation twice");'
```