[
{ start_status: 'WAT', finish_status: 'FNS', id: ['1-001'] },
{ start_status: 'WAT', finish_status: 'STP', id: ['1-002'] },
{ start_status: 'FNS', finish_status: 'WAT', id: ['2-002'] },
{ start_status: 'FNS', finish_status: 'WAT', id: ['2-003'] },
{ start_status: 'FNS', finish_status: 'WAT', id: ['2-004'] },
{ start_status: 'FNS', finish_status: 'WAT', id: ['2-005'] }
]
interface IUnitChange {
start_status: string,
finish_status: string,
id: string[],
}
const log_json: any = JSON.parse(JSON.stringify(arr));
const result: IUnitChange[] = [];
log_json.map((row) => {
const data = result.find((value) => (value.start_status === row.start_status && value.finish_status === row.finish_status));
if (data === undefined) {
result.push(row);
}
else {
data.id.push(row.id);
}
})
console.dir(result,{depth: null});
=====>
[
{ start_status: 'WAT', finish_status: 'FNS', id: ['1-001'] },
{ start_status: 'WAT', finish_status: 'STP', id: ['1-002'] },
{ start_status: 'FNS', finish_status: 'WAT', id: ['2-002','2-003','2-004','2-005'] }
]
< /code>
Я хочу изменить массив json, как верхний экран.
[значение статуса] может быть добавлено.
, поэтому я не могу разветвляться с помощью оператора if.
Подробнее здесь: https://stackoverflow.com/questions/795 ... se-help-me