I have an one object which contains multiple objects like this below:
const productFields = {
category_id: {
key: 'category_id',
label: 'Category',
uri: '/products/category',
value: '',
items: []
},
product_name: {
key: 'product_name',
label: 'Product Name',
value: '',
items: []
}
};
Now I want to add one more property into product_name object. I am doing the normal way using spread operator.
const newNameFields = {
...productFields.product_name,
uri:`/products/${this.$route.params.id}/category/${this.categoryId}`
};
Now, I am creating new object like this:
const newField = Object.assign({}, category_id: productFields.category_id , product_name: newNameFields);
But, is there any good different logic to do that without initialize that many variables and single shot? It is kind of lame logic I am doing.