As we can't access data from Object directly or perform operations on that.Firstly we have to convert the object in an array format then only we can apply functions .
In JavaScript, you can access the properties and values of an object in several ways. Here are the most common methods:
1 . Dot Notation ()
_the popular one _
Ex:
const person = {
name: "John",
};
console.log(person.name); // Output: John
2 . Bracket Notation
(Suitable for when object contain spacing in key )
const person ={
first name='Panchi';
}
console.log(person['first name']);
const person = {
name: "John",
age: 30,
city: "New York"
};
console.log(Object.keys(person)); // Output: ["name", "age", "city"]
console.log(Object.values(person)); // Output: ["John", 30, "New York"]
console.log(Object.entries(person));// Output: [["name", "John"], ["age", 30], ["city", "New York"]]
** NOTE : Object.entries used to return array then on that resulting array we can apply like .map() or .filter function.**
Moreover Resulting array contain data like enum in key value pair
The above is the detailed content of How to access Objects?. For more information, please follow other related articles on the PHP Chinese website!