I have a JSON response with the key and the value, I want to filter only those whose weight is 1 Any help is greatly appreciated
{
"post": 1,
"bio": 1,
"hashtag": 0,
"profile": 0,
}
expected output
{
"post": 1,
"bio": 1
}
I have a JSON response with the key and the value, I want to filter only those whose weight is 1 Any help is greatly appreciated
{
"post": 1,
"bio": 1,
"hashtag": 0,
"profile": 0,
}
expected output
{
"post": 1,
"bio": 1
}
You can filter over Object.entries
.
const o = {
"post": 1,
"bio": 1,
"hashtag": 0,
"profile": 0,
};
let res = Object.fromEntries(Object.entries(o).filter(([k,v])=>v===1));
console.log(res);