After forEach loop the object values changes in all the indexes, how to limit it with the current index
resp = {
label:'flowers',
plants: [
{
plantLabel: 'rose',
plantCode: 'RS',
},
{
plantLabel: 'Jasmine',
plantCode: 'JAS',
},
{
plantLabel: 'Lotus',
plantCode: 'LU',
}
]
};
loop() {
let newArray = [];
let tempResp = this.resp;
const val = chunk(tempResp.plants, 1);
console.log(val);
val.forEach(plant => {
let pushValue = tempResp;
pushValue.plants= plant;
newArray.push(pushValue);
});
**//expected
// [
// {
// label:'flowers',
// plants: [
// {
// plantLabel: 'rose',
// plantCode: 'RS',
// }
// ]
// },{
// label:'flowers',
// plants: [
// {
// plantLabel: 'Jasmine',
// plantCode: 'JAS',
// }
// ]
// },{
// label:'flowers',
// plants: [
// {
// plantLabel: 'Lotus',
// plantCode: 'LU',
// }
// ]
// }
// ]**
But am getting results as
// [
// {
// label:'flowers',
// plants: [
// {
// plantLabel: 'Lotus',
// plantCode: 'LU',
// }
// ]
// },{
// label:'flowers',
// plants: [
// {
// plantLabel: 'Lotus',
// plantCode: 'LU',
// }
// ]
// },{
// label:'flowers',
// plants: [
// {
// plantLabel: 'Lotus',
// plantCode: 'LU',
// }
// ]
// }
// ]
Any help is appreciated