要删除一些键值对表单对象数组,请使用Postgres SQL作为数据库,如下例所示:
这是用户函数,返回用户详细信息对象,我们必须从行中删除“ api_secret”键:
function getCurrentUser(req, res, next) {
var userId = res.locals.userId;
console.log(userId)
db.runSQLWithParams("select * from users where id = $1", [userId], function(err, rows) {
if(err){
console.log(err)
}
var responseObject = {
_embedded: rows,
}
responseObject._embedded[0].api_secret = undefined
res.json(responseObject);
});
}
上面的函数以JSON响应的形式返回对象下面的内容
{
"_embedded": [
{
"id": "0123abd-345gfhgjf-dajd4456kkdj",
"secret_key: "secret",
"email": "abcd@email.com",
"created": "2020-08-18T00:13:16.077Z"
}
]
}
添加此行后,responseObject._embedded[0].api_secret = undefined
它给出以下结果作为JSON响应:
{
"_embedded": [
{
"id": "0123abd-345gfhgjf-dajd4456kkdj",
"email": "abcd@email.com",
"created": "2020-08-18T00:13:16.077Z"
}
]
}