Remove empty Objects from Array

后端 未结 4 1609
礼貌的吻别
礼貌的吻别 2021-01-21 16:35

I have a JavaScript-array with objects filled in and want to remove every object with no data. It might look like this:

var myArray = [ {id: \"28b\", text:\"Phil         


        
4条回答
  •  清酒与你
    2021-01-21 17:06

    try (ECMA5+):

    var myArrayFiltered = myArray.filter((ele) => {
      return ele.constructor === Object && Object.keys(ele).length > 0
    });
    

提交回复
热议问题