Problem 1: Log the property names and values using for... in loop.
Expected Result:
name: 'John'
age: 30
city: 'New York'
Problem 2:
Sum all of the values in each property and console.log
sum to test if it works.
Expected Result:
console.log(sum); // Output: 60
Problem 3: Create a new object with a modified property value. Each value should be multiplied by 2 in the new object.
Expected Result:
{a: 2, b: 4, c: 6}
In the for-of-loops.js
file, you are going to create yourself in an object that will look similar to mine.
You will need a name
, age
, hobbies
(in an array) and a boolean of isEngineer
which is set to true.
Task 1:
Using the method Object.values
, print each value of your object.
Task 2:
Using the method Object.keys
, print out and label each key and value on separate lines.
E.g
console.log('key:', [insert var name] );
console.log('value:', [insert var name] )
Task 3:
Using Object.entries
(which uses array destructing), print out each key and value on the same line.
Modify one of the for... of loops and print out each hobbie inside of the array.