I need to sort the following array by the 2nd element of the contained tuple. The process runs through, until the last element has passed. After that I get the exception
ERROR TypeError: Cannot read property '1' of undefined
Here is my used Code:
public list:Array<[string, number]> = new Array<[string, number]>();
//{["A", 0],["B", 8], ...}
...
var sorted = false
while (!sorted){
sorted = true;
this.list.forEach(function (element, index, array){
alert(element);
if (element[1] > array[index+1][1] ) {
array[index][1] = array[index+1][1];
array[index+1] = element;
sorted = false;
}
});
}
I can't get, why this isn't working