The Object type represents one of JavaScript's data types. It is used to store various keyed collections and more complex entities. In short ,Objects are variables too. But objects can contain many values.
// defining objects way 1
syntax :
const person = {
firstName: "John",
lastName: "Doe",
age: 50,
eyeColor: "blue"
};
// Accessing objects properties way 1
syntax :
objectName.propertyName ;
// Accessing objects properties way 2 (not preffered as it create ambiguity)
syntax :
objectName["propertyName"] ;
// print objects
syntax :
console.log( objectName) ;
// print objects in table form
syntax :
console.table( objectName) ;
// The key is a unique string that acts as an identifier for the value.
// The value can be of any type, including strings, numbers, booleans, arrays, functions, or even other objects.
// to print all keys
syntax :
console.log( Object.keys(objectName));
// print all values
syntax :
console.log( Object.values(objectName));
Example :
let appleProducts = [
{
name: "iPhone 13 Pro",
price: 999,
color: "Graphite",
storage: "128GB",
},
{
name: "iPad Pro",
price: 799,
color: "Silver",
storage: "128GB",
},
];