Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example:
- // var a = {a:[],b:[{o:{c:[],d:1,e:[],f:"",},g:null,h:true,},{i:false,j:function(){}}]};
- // emptyArrayToNull(a);
- function emptyArrayToNull(obj) {
- if (typeof obj === 'object' && obj !== null) {
- if (obj.constructor.name === 'Array') {
- if (obj.length === 0) {
- return null;
- }
- for (var i = 0; i < obj.length; i++) {
- obj[i] = emptyArrayToNull(obj[i]);
- }
- return obj;
- }
- for (var i in obj) {
- if (obj.hasOwnProperty(i)) {
- obj[i] = emptyArrayToNull(obj[i]);
- }
- }
- }
- return obj;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement