I'm attempting to sort an array of maps by a particular key/value within the maps.
Map<string, string>[]
I get back the following error,
Cannot assign to read only property '0' of object '[object Array]''
I'm trying to make heads or tails of this error but I feel like I'm not returning the correct value somewhere. I think my code looks mostly correct. I'm more concerned I may be trying to do something that is more difficult than I realize. Here is my code. I hard-coded the key for now just try and work through the problem and that key does exists. Any insight would be great. Thanks for looking.
sortGridData(data$ : Observable<Map<string, string>[]>) : Observable<Map<string, string>[]> {
const sortedData$ = combineLatest([data$, this.sort$]).pipe(
map(([data, sort]: [Map<string, string>[], SortDescriptor[]]) => {
data.sort((item1, item2) => {
return this.compareObjects(item1, item2, 'version')
})
return data;
})
);
return sortedData$;
}
compareObjects(object1 : Map<string, string>, object2: Map<string, string>, key) {
let item1 = object1.get(key);
let item2 = object2.get(key);
const obj1 = item1.toUpperCase()
const obj2 = item2.toUpperCase()
if (obj1 < obj2) {
return -1
}
if (obj1 > obj2) {
return 1
}
return 0
}
Sort Grid data is called at another point in my component. I'm not sure that is entirely relevant.