Training day 16 - JavaScript Basic to Beginners

Heloo people!!

for (let key in circle) console.log(key, circle[key])


The above code is used to iterate over the properties in the object.

- ```
for(let key of circle)
    console.log(key)

The above code will give an error. To solve it we have circle.keys() method to iterate through the keys. This method returns key as string.

-

    const circle = {
      radius: 1,
      draw() {
          console.log('draw');
      }
    };


    const another = {};

    for(let key in circle)
    another [key] = circle[key];

    //above for loop code is similar to the below one

    const another1 = Object.assign({}, circle);


const another = Object.assign({
color: 'yellow'
}, circle);


const another = {...circle};

This is called the spread operator.