const data = {
item: [],
item1: [
{
id: '1',
name: 'name1',
},
],
item2: [
{
id: '2',
name: 'name12',
},
],
item3: [
{
id: '3',
name: 'name3',
},
],
item4: [],
item5: [],
};
const data2 = {
item1: [
{
id: '1',
name: 'name1',
},
],
item2: [
{
id: '2',
name: 'name12',
},
],
item3: [
{
id: '3',
name: 'name3',
},
],
};
const newData = Object
.entries(data)
.reduce((acc, [ k, v ]) => (v.length && (acc[k] = v), acc), {});
Object.keys(data).forEach(n => data[n].length || delete data[n]);
Можно использовать Lodash.
const newData = _.pickBy(data, n => n.length);
// или
_.each(data, (v, k) => v.length || delete data[k]);