I have to update the value name attribute of my object at particular index. I am having index no and also array. This is my code,
this.menus.forEach(x => {
let temp = this.menus.findIndex(function (item) {
return item.name == 'Cost Center';
});
// this.menus.values[temp].name=this.newCC;
this.menus[temp].name=this.newCC;
console.log("menu temp",temp);
This is my array structure, Array(11)
0:{_id: "5acc9e6320a7d71ab8372120", name: "DashBoard", link: "dashboard", icon: "fa fa-list", key: "dashboard", …}
1: {_id: "5acc9e6320a7d71ab837211f", name: "My Products", link: "print-products", icon: "fa fa-barcode", key: "print-products", …}
2:{sequence: null, key: "my-saved-jobs", icon: "fa fa-file-text-o", link: "my-saved-jobs", name: "My Saved Jobs", …}
3:{sequence: null, key: "my-placed-orders", icon: "fa fa-list-alt", link: "my-placed-orders", name: "My Orders", …}
4:{_id: "5acc9e6320a7d71ab837211b", name: "Site Design Setup", link: "storefront-setup", icon: "fa fa-university", key: "storefront-setup", …}
5:{_id: "5acc9e6320a7d71ab8372118", name: "Reports", link: "reports", icon: "icon-report", key: "reports", …}
6:{_id: "5accb9425241ed3270585b93", name: "Print Service Category", link: "print-service-category", icon: "fa fa-tasks", key: "print-service-category", …}
7:{sequence: null, key: "my-saved-files", icon: "fa fa-floppy-o", link: "my-saved-files", name: "My Saved Files", …}
8:{sequence: null, key: "product-list", icon: "fa fa-list", link: "product-list", name: "Product List", …}
9:{_id: "5acc9e6320a7d71ab8372119", name: "Deal Code", link: "deal- code", icon: "fa fa-university", key: "deal-code", …}
10:{sequence: null, key: "cost-center", icon: "icon-costCenter", link: "cost-center", name: undefined, …}
length:11
can anyone help to solve my issue? Please reply.
Actually I was doing an mistake while writing code, this code should be written where we are getting response from backend i.e within the scope of success response. this is my new code,
this.httpService.save(UrlDetails.$getPaymentSetting, client)
.subscribe(response => {
if (response.responseCode == 200) {
let paymentSetting = response.responseData;
console.log("client PAYMENT RESPONSE ",paymentSetting);
if( paymentSetting.paymentOption.customPayment.length != 0){
<------Some Code----->
.
.
this.menus.forEach(x => {
let temp1 = this.menus.findIndex(function (item) {
return item.name == 'Cost Center';
});
let temp2 = this.menus.findIndex(function (item) {
return item.name == 'Deal Code';
});
this.menus[temp1].name= this.newCC;
this.menus[temp2].name= this.newDC;
});
}
})