close

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

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How to use lodash to find and return an object from Array? in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

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

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

    use lodash to find and return an object from Array The argument passed to the callback is one of the elements of the array. The elements of your array are objects of the form {description: ..., id: ...}.

  2. use lodash to find and return an object from Array

    use lodash to find and return an object from Array The argument passed to the callback is one of the elements of the array. The elements of your array are objects of the form {description: ..., id: ...}.

Method 1

The argument passed to the callback is one of the elements of the array. The elements of your array are objects of the form {description: ..., id: ...}.

var delete_id = _.result(_.find(savedViews, function(obj) {
    return obj.description === view;
}), 'id');

Yet another alternative from the docs you linked to (lodash v3):

_.find(savedViews, 'description', view);

Lodash v4:

_.find(savedViews, ['description', view]);

Method 2

You can use the following

import { find } from 'lodash'

Then to return the entire object (not only its key or value) from the list with the following:

let match = find(savedViews, { 'ID': 'id to match'});

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment