MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Object.keys, Object.values, Object.entries0%
Study Materials
JavaScript for IntermediateProgress 0%
1.1Block Scope with let & const1.2Template Literals1.3Destructuring Arrays and Objects1.4Default Parameters1.5Enhanced Object Literals
6.1Object.keys, Object.values, Object.entries6.2Object.assign()6.3Spread in Objects6.4Object Destructuring in Depth
HomeTutorialsJavaScript for IntermediateObject.keys, Object.values, Object.entries
Object.assign()

Object.keys, Object.values, Object.entries

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study Materials

Iterating over and introspecting objects has evolved significantly from the error-prone for...in loops of early JavaScript. Modern standards provide static methods on Object that return standard arrays of an object's enumerable own properties, integrating seamlessly with array methods like .map(), .filter(), and .forEach().


1. Object.keys()

Object.keys(obj) returns an array of a given object's own enumerable property names (keys):

1const config = {
2 theme: 'dark',
3 version: '2.4.0',
4 autoSave: true
5};
6 
7const keys = Object.keys(config);
8console.log(keys); // ['theme', 'version', 'autoSave']
9 
10// Checking if an object is empty
11const isEmpty = Object.keys(config).length === 0;

2. Object.values()

Object.values(obj) returns an array of a given object's own enumerable property values:

1const monthlySales = {
2 january: 12000,
3 february: 15500,
4 march: 18200
5};
6 
7const revenues = Object.values(monthlySales);
8console.log(revenues); // [12000, 15500, 18200]
9 
10const quarterTotal = revenues.reduce((sum, val) => sum + val, 0);
11console.log('Q1 Revenue:', quarterTotal); // 45700

3. Object.entries()

Object.entries(obj) returns an array of a given object's own enumerable string-keyed [key, value] pairs:

1const userRoles = {
2 alice: 'Admin',
3 bob: 'Editor',
4 charlie: 'Viewer'
5};
6 
7const entries = Object.entries(userRoles);
8console.log(entries);
9// [
10// ['alice', 'Admin'],
11// ['bob', 'Editor'],
12// ['charlie', 'Viewer']
13// ]

Destructuring in Loops with for...of

1for (const [user, role] of Object.entries(userRoles)) {
2 console.log(`User ${user} has role permission: ${role}`);
3}

4. Reconstructing Objects with Object.fromEntries()

Object.fromEntries() performs the inverse of Object.entries(), transforming a list of key-value pairs back into an object. This enables filtering and transforming objects using standard array methods:

1 Original Object
2 │
3 ▼
4 Object.entries() ───► [ [k1, v1], [k2, v2] ]
5 │
6 .filter() / .map()
7 │
8 ▲ ▼
9 Object.fromEntries() ◄── [ [k1, newVal1] ]
10 │
11 Transformed Object

5. Why Object.keys() is Superior to for...in

1// AVOID: for...in iterates over inherited prototype properties!
2for (const key in obj) {
3 if (Object.hasOwn(obj, key)) { // Required boilerplate to prevent prototype leakage
4 console.log(key);
5 }
6}
7 
8// PREFERRED: Object.keys() only returns own enumerable properties
9Object.keys(obj).forEach(key => console.log(key));

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What does Object.keys({ a: 1, b: 2 }) return?
Question 2
How do you verify if a plain JavaScript object is completely empty ({})?
Question 3
Which method is the inverse of Object.entries(), converting [ [key, val], ... ] pairs back into an object?
Question 4
What does Object.entries({ score: 100 }) return?
Question 5
Why is Object.values() preferred over a manual for...in loop with obj[key]?
Next Lesson

Object.assign()

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Deep Copy vs Shallow CopyObject.assign()

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Intermediate with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext