I am trying to iterate over an array of array objects to de-dupe and sort the data within each. The function onlyUnique returns unique values in an array. The problem is, it doesn't work as intended.
arr_lists = [arr_1, arr_2, arr_3, arr_4, arr_5, ...]
for (var list_obj of arr_lists) {
list_obj = list_obj.join().split(',').filter(onlyUnique);
list_obj.sort();
Logger.log(list_obj);
}
The logger results show true (i.e. they are what I am looking for), but the original array is unchanged, although I think it should have been updated.
I've tried assigning the filtered array to a new array... nope. I know that I could add a thousand lines of code to achieve the results, but that seems silly.
I suspect it's something obvious.
list_obj = ...line inside the loop reassignslist_objto be a new array, so it is no longer a reference to one in the array. So sorting that array doesn't do anything to the original array.split(',')creates a new array, andfiltercreates again a new array. Your code is not sorting the original array. Unrelated, but why do you do.join().split(',')?.join().split(',')code while looking for an easy way to filter to unique values in a list. I never examined the logic at the time.