Filtering array of objects based on value

前端 未结 3 850
孤街浪徒
孤街浪徒 2021-01-21 12:49

Is there a way to filter an array of objects by a particular value that could be in any property?

Let\'s say I have this object:

var x = [
    {
                 


        
3条回答
  •  余生分开走
    2021-01-21 13:02

    use an inner loop method to check individual property values

    var val ="one";
    var res = x.filter(function(item){
         return Object.keys(item).some(function(prop){
             return item[prop] === val;
         });
    });
    

提交回复
热议问题