[Fixed] How to push object into array angular 8

Issue

i am getting below example data in this.selectedParameterContext.

Solution

Please try the below code.

deleteAllContextData(data) {
const newSelectedParameterContext = {
  'records': []
};   
this.selectedParameterContext.records.forEach(function (record) {
  const newSelectedParameterValues = [];
  record.values.forEach(function (parameter, parameterIndex) {
    const isValid = data.data.values.find(function (item) {
      return parameter.value === item.value && parameter.label === item.label;
    });
    if (isValid) {
      newSelectedParameterValues.push(parameter);
    }
  });     
  newSelectedParameterContext.records.push({ ...record, 'values': newSelectedParameterValues });
}); 
this.selectedParameterContext = newSelectedParameterContext;

}

Leave a Reply

(*) Required, Your email will not be published