1 回答

TA貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個(gè)贊
您可以使用正則表達(dá)式來獲取所有已翻譯的 ID。讓我們假設(shè)它們都是T<number>T格式的,這看起來是真的。
const input = 'T4T____T5T____T2T____T10T____T6T____';
const dictEntries = [...dict.entries()].map(([id, translatedId]) => ({id, translatedId}));
const output = input
.match(/T\d+T/g)
.map(translatedId => dictEntries.find(entry => entry.translatedId === translatedId))
.filter(entry => entry !== undefined)
.map(entry => entry.id);
// ["00:00:00:02:89:51", "00:00:00:02:27:bd", "00:00:00:02:89:af", "00:00:00:02:89:28", "00:00:00:02:89:31"]
output.join(', ')如果你想要它作為逗號(hào)分隔的字符串,你可以得到。
添加回答
舉報(bào)