I am working on angular 6. I have an array of objects(got from an API). The objects have similar properties and I want to attach different values to each element with the property name of "value".BUT the values I‘m giving are being attached to all elements of the array.
Tried to give a unique id for each object to differentiate one from the other. But a single unique key is assigned to all similar object elements.
uniqueFields = [
{
name: "ProformaInvoiceNumber",
type: "text",
options: Array(0),
isCommon: false,
required: true
},
{
name: "ProformaInvoiceDate",
type: "date",
options: Array(0),
isCommon: false,
required: true
},
{
name: "ProformaInvoiceNumber",
type: "text",
options: Array(0),
isCommon: false,
required: true
},
{
name: "ProformaInvoiceDate",
type: "date",
options: Array(0),
isCommon: false,
required: true
}];
//received values from html form
recievedValues = [1, {name }, 2, { obj2 }];
//give values to my uniqueFields from the array recievedValues
this.uniqueFields.foreach((element, i) => {
element.value = recievedValues[i];//both arrays have the same length
});
Was expecting an array with objects, and each objects having property "value" and the value from the corresponding array element. Instead, I am getting this...
uniqueFields = [
{
name: "ProformaInvoiceNumber",
type: "text",
options: Array(0),
isCommon: false,
required: true,
value: 2
},
{
name: "ProformaInvoiceDate",
type: "date",
options: Array(0),
isCommon: false,
required: true,
value: { obj2 }
},
{
name: "ProformaInvoiceNumber",
type: "text",
options: Array(0),
isCommon: false,
required: true,
value: 2
},
{
name: "ProformaInvoiceDate",
type: "date",
options: Array(0),
isCommon: false,
required: true,
value: { obj2 }
}];