I want to do bulk update to an array using typescript.
I did it by using for loop.
this.versions = [{ id: 1, VersionName: 'test1' }, { id: 2, VersionName: 'test2' }, { id: 3, VersionName: 'test3' }, { id: 4, VersionName: 'test4' }];
this.selectedVersions = [{ id: 2, VersionName: 'test2' }, { id: 3, VersionName: 'test3' }];
for (let i = 0; i < this.selectedVersions.length; i++) {
this.versions = this._configuration.updateEveryObjectsByKey(this.versions, this.selectedVersions[i], "Id");
}
updateEveryObjectsByKey(listOfdata: any, data: any, key: string) {
listOfdata = listOfdata.map(function (item) {
return item[key] == data[key] ? data : item;
})
return listOfdata;
}
But I don't like to use for loop. So let me know how to do bulk update to array using typescript?