Hi I am developing AngularJS 2 application. I am trying to create new array from existing array. I have my below array.
[
{
"roleid":"666c01aa-5272-40bc-a888-5edac9087aad",
"ischecked":"false",
"rolename":"Observer",
"tenantid":"3a8360d6-9491-4191-a1ea-3260b70c3cd2",
"isactive":true,
"isdeleted":false,
"scopeids":null,
"scopes":null
},
{
"roleid":"4df4bf2f-16b0-482a-84c1-7a646bbfcf71",
"ischecked":"true",
"rolename":"Operator",
"tenantid":"3a8360d6-9491-4191-a1ea-3260b70c3cd2",
"isactive":true,
"isdeleted":false,
"scopeids":null,
"scopes":null
}
]
I have one more array dropdownList = [];
In the first array i have properties roleid and rolename. I want to reproduce my first array into as below.
this.dropdownList = [
{"id":666c01aa-5272-40bc-a888-5edac9087aad,"itemName":"Observer"},
{"id":4df4bf2f-16b0-482a-84c1-7a646bbfcf71,"itemName":"Operator"}
]
I want to copy roleid and roename into id and itemName in dropdownList array. I tried as below.
var id, itemName;
results.forEach(eachObj => {
this.dropdownList.push(
id = eachObj.roleid,
itemName = eachObj.rolename);
});
Here result is my first array. I am looping through each row and pushing to dropdownList. This results in sequence of rows starting from index 0 but i wanted as i shown above. Can someone help me to make this works? Any help would be appreciated. Thank you.