All my AJAX requests are in json format which are being parsed in javascript.
How can i prevent null values being displayed in an HTML page without needing to write an if-statement in javascript for each json value?
Or should i write a custom PHP function to encode an array to json instead of using json_encode() so it doesn’t display ‘null’ ?
In server side with PHP,
You can use
array_filterbeforejson_encode.array_filterwithout second argument removes null elements of entry array, example :The
$resultcontains:As you see, the null elements are removed.