Hello everyone, thank you very much in advance for your answers and comments, I am trying the following:
I have an array of Objects in which I want to add a new key and value to all the objects, I have the following object:
const pension = [
{cat_bank_id: 91,cat_discount: 1,clabe: "901",curp: "ASDA",name: "asda",percentage: "12"},
{cat_bank_id: 92,cat_discount: 1,clabe: "902",curp: "ASDB",name: "asdb",percentage: "12"}
];
I want to achieve the following:
const pension = [
{cat_bank_id: 91,cat_discount: 1,clabe: "901",curp: "ASDA",name: "asda",percentage: "12", employee_id: 212},
{cat_bank_id: 92,cat_discount: 1,clabe: "902",curp: "ASDB",name: "asdb",percentage: "12", employee_id: 212}
];
I am trying as follows:
const pension = [
{cat_bank_id: 91,cat_discount: 1,clabe: "901",curp: "ASDA",name: "asda",percentage: "12"},
{cat_bank_id: 92,cat_discount: 1,clabe: "902",curp: "ASDB",name: "asdb",percentage: "12"}
];
const employee_id = 212;
const test = pension.map(pension => {
return pension.key3 = employee_id;
});
console.log(test)
You must create a new object or append it. The spread operator can be useful.
Another way to do it: