How to assign one variable value to new variable value in Javascirpt Angular2 : I trying to creating a new dynamic array. I assigned one dynamic variable value to another new variable and pushing new array. But updating last array variable value. How to do without setTimout(function()) 

Code
----

    for(let i=0;i<allItems.length;i++){              
                let categories = allItems[i].categories;
                    for(let j=0;j<categories.length;j++){
                        let categoryId = categories[j].id;
                        //console.log("categories[j].id ", categoryId);
                        allItems[i]['categoryId'] = categoryId;
                            reitems.push(allItems[i]);
                      
                }
    }

My Json Value:
--------------

    [{
        
        "itemName" : "3 SS Finish Baskets",
        "itemDesc" : "3 SS Finish Baskets",
        "itemId" : 1,
        "unitId" : 2,
        "categories" : [ 
            {
                "id" : 1,
                "text" : "single room"
            },
            {
                "id" : 2,
                "text" : "Foyer/Living"
            } 
        ]
    },
    {
    ....
    }]

Output
------

    [{
        
        "itemName" : "3 SS Finish Baskets",
        "categoryId " : 2
    },
    {
        "itemName" : "3 SS Finish Baskets",
        "categoryId " : 2
    }]

Expecting Output
----------------

    [{
        
        "itemName" : "3 SS Finish Baskets",
        "categoryId " 1
    },
    {
        "itemName" : "3 SS Finish Baskets",
        "categoryId " 2
    }]

