Explaining that javascript objects are a way of saving multiple data, such as string
, boolean
, int
, float
, etc.
You can create an object called cellular , the cell phone has three or more data, some of them are color, brand, capacity.
The color
can vary, it can be black and gray at the same time, we can
put it together in the following way:
var celular = {
color: ['negro', 'gris'],
marca: 'iPhone',
capacidad: 64
}
console.log(celular)
As we can see in the object celular.color
there is and more than one data, they can be more if you want.
var celular = {
color: ['negro', 'gris'],
marca: 'iPhone',
capacidad: 64
}
console.log(celular.color)
But we can add more data to my object celular
, we can add modelo
.
var celular = {
color: ['negro', 'gris'],
marca: 'iPhone',
capacidad: 64
}
celular.modelo = '6S'
console.log(celular)
In this way we modify our object by adding a new data called model, this data is a string
, we can add another data that is an object ..
var celular = {
color: ['negro', 'gris'],
marca: 'iPhone',
capacidad: 64
}
celular.modelo = '6S'
var aplicaciones = [
{
nombre: 'whatsapp',
peso: 120,
},
{
nombre: 'facebook',
peso: 160,
}
]
celular.aplicaciones = aplicaciones
console.log(celular)
In this way we add a list of objects in an object.