-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07-objetos.js
42 lines (34 loc) · 953 Bytes
/
07-objetos.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Objetos
// Notacion Literal: Inicializacion de objetos
const movie = {
name: 'Joker',
releaseDate: '2019-10-04',
time: 2,
adult: false,
genres: ['crime', 'drama'],
status: {
released: true,
score: 0.82
}
};
console.log('movie', movie);
// Accediendo a las propiedades de un objeto
console.log('name', movie.name);
console.log('status.released', movie.status.released);
// Object destructuring
const {time, genres} = movie;
console.log('time', time);
console.log('genres', genres);
// Asignacion sin declaracion
({movieName, release} = {movieName: movie.name, release: movie.releaseDate});
console.log(movieName, release);
// Agregar propiedades
movie.director = 'Todd Phillips';
console.log(movie);
// Objeto a Cadena
const movieString = JSON.stringify(movie);
console.log(movieString);
// Cadena a Objeto
const movieObj = JSON.parse(movieString);
console.log(movieObj);
console.log(movieObj.name);