To remove some key value pair form object array uses Postgres SQL as database like this example:
This is user function return user details object, we have to remove "api_secret" key from rows :
function getCurrentUser(req, res, next) { // user function
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
// console.log(api);
// console.log(responseObject);
res.json(responseObject);
});
}
The above function return below object as JSON response before
{
"_embedded": [
{
"id": "0123abd-345gfhgjf-dajd4456kkdj",
"secret_key: "secret",
"email": "[email protected]",
"created": "2020-08-18T00:13:16.077Z"
}
]
}
After adding this line responseObject._embedded[0].api_secret = undefined
It gives below result as JSON response:
{
"_embedded": [
{
"id": "0123abd-345gfhgjf-dajd4456kkdj",
"email": "[email protected]",
"created": "2020-08-18T00:13:16.077Z"
}
]
}