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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.