Day 86: Convert Object to Array of Key-Value Pair | 100 Days of JavaScript Coding Challenge

Опубликовано: 07 Апрель 2025
на канале: Code with Poonam
59
6

🎯 Welcome to Day 86 of the 100 Days of JavaScript Coding Challenge! 🚀
#CodeWithPoonam #100DaysOfCode

📥 Problem Statement:
Write a JavaScript function to return an array of objects containing both key and value pairs from an object.

📊 Example:

Input:
{ a: 1, b: 2, c: 3 }
Output: [ { key: 'a', value: 1 }, { key: 'b', value: 2 }, { key: 'c', value: 3 } ]

Input:
{ name: "John", age: 30, city: "New York" }
Output: [ { key: 'name', value: 'John' }, { key: 'age', value: 30 }, { key: 'city', value: 'New York' } ]

Input:
{}
Output: []

💡 Approach:
✅ Step 1: Use Object.entries() to extract key-value pairs as an array.
✅ Step 2: Use the map() method to transform the array into an array of objects.
✅ Step 3: Destructure each key-value pair inside the map() loop.
✅ Step 4: Return the final array of objects.

📚 Key Concepts Used:
✅ Object.entries(): Converts an object into an array of key-value pairs.
✅ Array.prototype.map(): Iterates and transforms elements of an array.
✅ Destructuring: [key, value] to directly extract elements from an array.

📅 On Day 86, you learned how to transform an object into an array of objects containing key-value pairs using Object.entries() and the map() method.

🔥 Keep coding and stay consistent!
📩 #JavaScript #CodingChallenge #100DaysOfCode #CodeWithPoonam #LearnJavaScript

javascript coding challenge, javascript Coding Challenge Interview Questions 2024, javascript coding interview, javascript array interview questions answers, javascript reduce interview questions, javascript coding questions, javascript coding challenges for beginners, javascript coding examples, javascript interview coding exercises, javascript interview questions and answers for experienced and freshers.#javascriptcoding
javascript coding challenge, javascript Coding Challenge Interview Questions 2024, javascript coding interview, javascript array interview questions answers, javascript strings interview questions answers, javascript object interview questions answers, javascript math interview questions, javascript reduce interview questions, javascript coding interview questions and answers, javascript coding for beginners, javascript coding questions, javascript coding challenges for beginners, javascript coding examples, javascript interview coding exercises, javascript interview questions and answers for experienced and freshers.

Javascript interview questions and answers, javascript interview questions, javascript interview coding exercises, javascript interview questions and answers 2024, javascript interview questions and answers 2023, javascript interview prep, javascript in 12 minutes.