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

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

My objects:

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


        
10条回答
  •  日久生厌
    2020-11-29 20:01

    You don't need Lodash or Ramda or any other extra dependency.

    Just use the ES6 find() function in a functional way:

    savedViews.find(el => el.description === view)
    

    Sometimes you need to use 3rd-party libraries to get all the goodies that come with them. However, generally speaking, try avoiding dependencies when you don't need them. Dependencies can:

    • bloat your bundled code size,
    • you will have to keep them up to date,
    • and they can introduce bugs or security risks

提交回复
热议问题