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
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3