2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								id: 56533eb9ac21ba0edf2244c7
							 
						 
					
						
							
								
									
										
										
										
											2021-03-08 07:28:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								title: Accede a propiedades de objetos con notación de puntos
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								challengeType: 1
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								videoUrl: 'https://scrimba.com/c/cGryJs8'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								forumTopicId: 16164
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								dashedName: accessing-object-properties-with-dot-notation
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# --description--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-03-08 07:28:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Hay dos maneras de acceder a las propiedades de un objeto: notación de puntos (`.` ) y notación de corchetes (`[]` ), similar a un arreglo.
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-03-08 07:28:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								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.
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-03-08 07:28:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Aquí hay un ejemplo de cómo usar la notación de puntos (`.` ) para leer la propiedad de un objeto:
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								var myObj = {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  prop1: "val1",
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  prop2: "val2"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								};
							 
						 
					
						
							
								
									
										
										
										
											2021-03-08 07:28:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var prop1val = myObj.prop1;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								var prop2val = myObj.prop2;
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-03-08 07:28:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`prop1val`  tendrá una cadena con valor `val1`  y `prop2val`  tendrá una cadena con valor `val2` . 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# --instructions--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-03-08 07:28:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								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.
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# --hints--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-03-08 07:28:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`hatValue`  debe ser una cadena 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert(typeof hatValue === 'string');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-03-08 07:28:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								El valor de `hatValue`  debe ser la cadena `ballcap` 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert(hatValue === 'ballcap');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-03-08 07:28:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`shirtValue`  debe ser una cadena 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert(typeof shirtValue === 'string');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-03-08 07:28:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								El valor de `shirtValue`  debe ser la cadena `jersey` 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert(shirtValue === 'jersey');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-03-08 07:28:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Debes usar la notación de puntos dos veces
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```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;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```