title: Assigning array inside object in Javascript
body: <p>I have <code>cart</code> and <code>products</code> global variable.</p>
  
  <p>Products can have multiple attributes. </p>
  
  <p>Here is a code</p>
  
  <pre><code>var products = [
                    {
                      name: 'Table',
                      price: 200,
                      attributes: [
                                    {
                                      name: 'Height',
                                      type: 'text',
                                      default_value: '',
                                    },
                                    {
                                      name: 'Width',
                                      type: 'text',
                                      default_value: '',
                                    }
                                  ],
                    },
                    {
                      name: 'Chair',
                      price: 150,
                      attributes: [
                                    {
                                      name: 'Height',
                                      type: 'text',
                                      default_value: '',
                                    },
                                    {
                                      name: 'Width',
                                      type: 'text',
                                      default_value: '',
                                    },
                                    {
                                      name: 'Company',
                                      type: 'text',
                                      default_value: ''
                                    }
                                  ],
                    }
                ];
  
  var cart = {
    products: [],
  };
  
  //console.log('Initial cart',cart);
  
  //add product to cart
  let p = Object.assign({},products[0]);
  cart.products.push(p);
  
  //console.log('First cart', cart);
  //change price
  cart.products[0].price = 20;
  //console.log('products',products);
  //console.log('second cart',cart);
  
  //change attribute of product
  cart.products[0].attributes[0].value = 5;
  </code></pre>
  
  <p>This code changes global <code>products</code> <code>value</code> attributes instead of cart attributes.</p>
  
  <p>Please help me to solve this issue. </p>