Files
freeCodeCamp/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md
camperbot 7c3cbbbfd5 chore(i18n,learn): processed translations (#41416)
* chore(i8n,learn): processed translations

* Update curriculum/challenges/chinese/01-responsive-web-design/applied-visual-design/use-the-u-tag-to-underline-text.md

Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>

Co-authored-by: Crowdin Bot <support+bot@crowdin.com>
Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com>
Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>
2021-03-08 06:28:46 -08:00

100 lines
2.1 KiB
Markdown

---
id: 56533eb9ac21ba0edf2244c7
title: Accede a propiedades de objetos con notación de puntos
challengeType: 1
videoUrl: 'https://scrimba.com/c/cGryJs8'
forumTopicId: 16164
dashedName: accessing-object-properties-with-dot-notation
---
# --description--
Hay dos maneras de acceder a las propiedades de un objeto: notación de puntos (`.`) y notación de corchetes (`[]`), similar a un arreglo.
La notación de puntos es lo que se usa cuando conoces el nombre de la propiedad a la que intentas acceder con antelación.
Aquí hay un ejemplo de cómo usar la notación de puntos (`.`) para leer la propiedad de un objeto:
```js
var myObj = {
prop1: "val1",
prop2: "val2"
};
var prop1val = myObj.prop1;
var prop2val = myObj.prop2;
```
`prop1val` tendrá una cadena con valor `val1` y `prop2val` tendrá una cadena con valor `val2`.
# --instructions--
Lee los valores de las propiedades de `testObj` utilizando la notación de puntos. Asigna la variable `hatValue` igual a la propiedad `hat` del objeto y asigna la variable `shirtValue` igual a la propiedad `shirt` del objeto.
# --hints--
`hatValue` debe ser una cadena
```js
assert(typeof hatValue === 'string');
```
El valor de `hatValue` debe ser la cadena `ballcap`
```js
assert(hatValue === 'ballcap');
```
`shirtValue` debe ser una cadena
```js
assert(typeof shirtValue === 'string');
```
El valor de `shirtValue` debe ser la cadena `jersey`
```js
assert(shirtValue === 'jersey');
```
Debes usar la notación de puntos dos veces
```js
assert(code.match(/testObj\.\w+/g).length > 1);
```
# --seed--
## --after-user-code--
```js
(function(a,b) { return "hatValue = '" + a + "', shirtValue = '" + b + "'"; })(hatValue,shirtValue);
```
## --seed-contents--
```js
// Setup
var testObj = {
"hat": "ballcap",
"shirt": "jersey",
"shoes": "cleats"
};
// Only change code below this line
var hatValue = testObj; // Change this line
var shirtValue = testObj; // Change this line
```
# --solutions--
```js
var testObj = {
"hat": "ballcap",
"shirt": "jersey",
"shoes": "cleats"
};
var hatValue = testObj.hat;
var shirtValue = testObj.shirt;
```