nodejs - 如何删除定界符后的部分字符串
nodejs - how to remove part of a string after a delimiter
我在 nodejs 脚本中使用此代码将一些元素推送到 list
查询类型的数组中。
for (let [index, torrent] of results.entries()) {
if (torrent.seeds > 0 && torrent.peers > 0) {
filesList.push(`${torrent.title} s:${torrent.seeds} p:${torrent.peers}`);
filesDetails.push(torrent);
} else {
results.splice(index, 1);
}
}
如您所见,我在文件名后添加 s:value
和 p:value
以告知用户文件的种子和对等项。当用户 select 列表中的文件时,我正在搜索对象数组以找到该文件并将其返回。如果我不将 s:value
和 p:value
添加到文件名,一切都按预期工作,但由于我需要提供此信息,我如何在循环之前将它们从文件名中删除数组?
这是我目前用来在对象数组中找到正确文件的代码
const selectedTorrent = [];
for (let f of filesDetails) {
if (f.title === availableTorrents.selected) {
selectedTorrent.push(f);
}
}
我在 nodejs 脚本中使用此代码将一些元素推送到 list
查询类型的数组中。
for (let [index, torrent] of results.entries()) {
if (torrent.seeds > 0 && torrent.peers > 0) {
filesList.push(`${torrent.title} s:${torrent.seeds} p:${torrent.peers}`);
filesDetails.push(torrent);
} else {
results.splice(index, 1);
}
}
如您所见,我在文件名后添加 s:value
和 p:value
以告知用户文件的种子和对等项。当用户 select 列表中的文件时,我正在搜索对象数组以找到该文件并将其返回。如果我不将 s:value
和 p:value
添加到文件名,一切都按预期工作,但由于我需要提供此信息,我如何在循环之前将它们从文件名中删除数组?
这是我目前用来在对象数组中找到正确文件的代码
const selectedTorrent = [];
for (let f of filesDetails) {
if (f.title === availableTorrents.selected) {
selectedTorrent.push(f);
}
}