How to use lodash to find and return an object from Array?

前端 未结 10 1106
终归单人心
终归单人心 2020-11-29 18:58

My objects:

[
    {
        description: \'object1\', id: 1
    },
    {
        description: \'object2\', id: 2
    }
    {
        description: \'object3\         


        
10条回答
  •  死守一世寂寞
    2020-11-29 19:43

    With the find method, your callback is going to be passed the value of each element, like:

    {
        description: 'object1', id: 1
    }
    

    Thus, you want code like:

    _.find(savedViews, function(o) {
            return o.description === view;
    })
    

提交回复
热议问题