loading...

re: Lodash and Underscore, is there still a case? VIEW POST

TOP OF THREAD FULL DISCUSSION
re: I don't think one method does exist off the top of my head. Can you give me a data structure snippet to visualize. I guess you might want to use e...

So, if your data structure is

[{firstName: 'John', lastName: 'Smith', offspring: [{name:'Katie', gender: 'F'}, {name: 'Mark', gender: 'M'}],
{firstName: 'Jill', lastName: 'Jones', offSpring: [{name: 'Doug', gender: 'M'}]}]

and you're looking for someone whose firstborn is a son (in case of pestilence), you can do _.find(users, ['offspring[0].gender', 'M'])

Or if you want the last name of the second user, you can do _.get(users, '[1].lastName')

Or if you want to find all users with offspring
_.filter(users, 'offspring.length')

I just don't see easily being able to do that with native ES6 functions out of the box.

const arr = [{
    firstName: 'John',
    lastName: 'Smith',
    offspring: [{
        name:'Katie', 
        gender: 'F'
    }, {
        name: 'Mark',
        gender: 'M'
    }],
    {
        firstName: 'Jill', 
        lastName: 'Jones', 
        offSpring: [{
            name: 'Doug', 
            gender: 'M'
        }]
    }
];

arr.find(person => person.offspring.find ... // Point taken this is a bit more wordy๐Ÿ˜

So in other words, you can't do it out of the box with ES6 functions--you have to write additional functionality yourself (which your team is then responsible for testing and maintaining).

Code of Conduct Report abuse