Эти данные хранятся как запись < /code>, где ключ генерируется с использованием индекса в массиве. Сценарий:
[ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' ]
массив затем фильтруется вне моей функции. Старый массив неизвестен, все, что остается, - это следующие данные: < /p>
- Новый массив ['a', 'b', 'd', 'e', 'h', 'i', 'j'] < /code>. Помните, что это неизвестно [] и не отсортирован. В этом случае это будет [2, 5, 6] (соответствует ['c', 'f', 'g'] )
- Длина массива до его фильтрации. В этом случае 10
Мне не нужно удалять висящие данные с конца массива. Все данные в записи от фильтра.function getKey(i: number) {
return `unknownProcess[${i}]`;
}
// Array before the filter
const originalArray = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' ]
// Associated data is the upper case variant of the letter
const associatedData: Record = {}
originalArray.forEach((letter, i) => {
associatedData[getKey(i)] = letter.toUpperCase();
});
// data[getKey(0)] === 'A'
// data[getKey(2)] === 'C'
// Array after filter
// [ 'a', 'b', 'd', 'e', 'h', 'i', 'j' ]
// data[getKey(0)] === 'A'
// data[getKey(2)] === 'C' // should be 'D' now
// data[getKey(4)] === 'E' // should be 'H' now
type FooData = any
// separate file, cannot access data above
function shiftDataFromFilter(filteredArray: unknown[], data: Record, removedIndeces: number[], lengthBeforeFilter: number) {
// to get data of index 0
const fooData = data[getKey(0)];
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... ilter-data
Мобильная версия