JSFiddle - React, Tailwind, and code Playground
JavaScript
$(function(){
var test = {"code_operateur":[""],"cp_cult":["something",""],
"annee":["2011"],"ca_cult":[""]}
function isEmpty(thingy) {
return thingy.length == 0;
}
function removeEmpties(thingy) {
var res = [];
for(var i in thingy) {
if(thingy[i]) {
res.push(thingy[i]);
}
}
return res;
}
for(i in test) {
if(typeof test[i] == "object") {
test[i] = removeEmpties(test[i]);
}
if ( test[i] == "" || test[i] === null || (typeof test[i] == "object" && isEmpty(removeEmpties(test[i]))) ) {
delete test[i];
}
}
for(var i in test) {
document.write(i+": "+test[i]+"<br>");
}
});