Aryan PrajapatKnowledge Contributor
What is the main difference between Object.values and Object.entries method
What is the main difference between Object.values and Object.entries method
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Questions | Answers | Discussions | Knowledge sharing | Communities & more.
The Object.values() method’s behavior is similar to Object.entries() method but it returns an array of values instead [key,value] pairs.
const object = {
a: “Good morning”,
b: 100,
};
for (let value of Object.values(object)) {
console.log(`${value}`); // ‘Good morning \n100’
}
The order of the array returned by Object.values() is the same as that provided by a for…in loop. If you need the property keys, use Object.keys() instead. If you need both the property keys and values, use Object.entries() instead