Object Values and Entries in JavaScript
Level 3141 keystrokes
Object.values() returns property values, Object.entries() returns key-value pairs.
JavaScript code
// Create an object with three properties1const obj = { a: 1, b: 2, c: 3 };// Object.values() returns an array of values// Returns [1, 2, 3]2console.log(Object.values(obj));// Object.entries() returns array of [key, value] pairs// Returns [["a", 1], ["b", 2], ["c", 3]]3console.log(Object.entries(obj));// Get the number of properties using entries length (3)4console.log(Object.entries(obj).length);Output
[ 1, 2, 3 ] [ [ 'a', 1 ], [ 'b', 2 ], [ 'c', 3 ] ] 3
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this JavaScript code and how often they appear.
.× 7(× 6)× 6;× 4:× 3,× 2{× 1}× 1=× 1