我有一个数组,clients我想array.find()在其上运行。该数组包含对象,通常看起来像这样:
[ { customId: 'user1', clientId: 'TPGMNrnGtpRYtxxIAAAC' },
{ customId: 'user2', clientId: 'G80kFbp9ggAcLiDjAAAE' } ]
Run Code Online (Sandbox Code Playgroud)
这是我遇到问题的地方。我试图用它来find()查看数组中的任何对象(或对象的一部分)是否与某个变量 匹配,recipient该变量通常包含类似 的值user1。我用来执行此操作的代码是:
function checkID(recipient) {
return recipient;
}
var found = clients.find(checkID);
Run Code Online (Sandbox Code Playgroud)
这始终返回数组中的第一个对象。我是否使用find()错误,或者有更好的方法来做到这一点?
我正在开发一个应用程序,它有一个服务器,可以使用response.download(). (我正在使用 node.js、express 和 fs)一旦这些文件被下载,它们就会占用空间,所以我尝试fs.unlinksync在下载后调用以摆脱它们。但是没有这样的运气:我只是收到以下错误:NOENT: No such file or directory.
这是相关的服务器端代码:
app.get("/file", function(request, response) {
var filename = request.query.f;
var filePath = "public/" + filename
response.download(filePath);
//this is where I've tried putting fs.unlink
});
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激。谢谢!