有人可以帮我附加一个对象吗?例如,我有原始对象:

var object = {
    { product_code: '55993',
      brand: 'Phillips66',
      category: 'LUBES AND GREASES',
      description: 'cuatro cinco seis',
      price: '300.00',
      quantity: '3'
    }
}

我想追加:
    { product_code: '90210',
      brand: 'Phillips66',
      category: 'LUBES AND GREASES',
      description: 'cuatro cinco seis',
      price: '500.00',
      quantity: '5'
    }

所以最后,object看起来像:
object = {
    { product_code: '55993',
      brand: 'Phillips66',
      category: 'LUBES AND GREASES',
      description: 'cuatro cinco seis',
      price: '300.00',
      quantity: '3'
    },
    { product_code: '90210',
      brand: 'Phillips66',
      category: 'LUBES AND GREASES',
      description: 'cuatro cinco seis',
      price: '500.00',
      quantity: '5'
    }
}

我怎么做?

最佳答案

您可以使用ES6传播运算符来附加对象。

object = { ...object,
...{ product_code: '90210',
      brand: 'Phillips66',
      category: 'LUBES AND GREASES',
      description: 'cuatro cinco seis',
      price: '500.00',
      quantity: '5'
    }
}

09-07 17:08