Sharepoint Dev - REST API

You can use it as value.Department ? value.Department : "" which is a JS ternary operator.

Basically it acts like an if condition as below:

if(value.Department){
    value.Department = value.Department;
}else{
    value.Department = "";
}

You need to do this for other fields as well to check for undefined or null values and convert them to empty string.