0
0
Javascriptprogramming~10 mins

Object entries in Javascript - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get an array of key-value pairs from the object.

Javascript
const obj = {a: 1, b: 2};
const entries = Object.[1](obj);
console.log(entries);
Drag options to blanks, or click blank then click option'
Aentries
Bentries()
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using Object.keys instead of Object.entries
Forgetting to call the method with parentheses
2fill in blank
medium

Complete the code to loop over the entries of the object.

Javascript
const obj = {x: 10, y: 20};
for (const [key, value] of Object.[1](obj)) {
  console.log(key, value);
}
Drag options to blanks, or click blank then click option'
AgetEntries
Bentries
Cvalues
Dkeys
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using Object.keys which returns only keys
Using Object.values which returns only values
3fill in blank
hard

Fix the error in the code to correctly get entries from the object.

Javascript
const obj = {name: 'Alice', age: 25};
const entries = Object.[1](obj);
console.log(entries);
Drag options to blanks, or click blank then click option'
Aentrys
Bentry
Centires
Dentries
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Misspelling the method name
Using singular form 'entry'
4fill in blank
hard

Fill both blanks to create an object from entries and log it.

Javascript
const entries = [['a', 1], ['b', 2]];
const obj = Object.[1](entries);
console.[2](obj);
Drag options to blanks, or click blank then click option'
AfromEntries
Blog
Cprint
Dentries
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using Object.entries instead of fromEntries
Using console.print which is not a function
5fill in blank
hard

Fill all three blanks to filter entries with values greater than 10 and create a new object.

Javascript
const obj = {a: 5, b: 15, c: 25};
const filteredEntries = Object.entries(obj).filter(([[1], [2]]) => [3] > 10);
const newObj = Object.fromEntries(filteredEntries);
console.log(newObj);
Drag options to blanks, or click blank then click option'
Akey
Bvalue
Cval
Dk
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using wrong variable names in destructuring
Comparing key instead of value