I want to filter JSON to check if pre-defined keys are exist in that or not. php example code for that is :
$search = json_decode($request->get('search'),true);
// Get only required params
$search = array_filter($search, function($k){
return $k == 'id' || $k == 'name' || $k == 'filterText' || $k == 'isEnable';
}, ARRAY_FILTER_USE_KEY);
The abve code give me output when filterText and isEnable is present in query, output will be somthing like this (with key and value) :
{
"isEnable": 1,
"filterText": "a"
}
How do I accomplish this in javascript. I need code for javascript and not jquery
My json will look like :
{ question: 'aaa', answer: 'bbb' }