0

I've been trying to sort an array by a value within a nested array, data.Count. Unfortunately, I cannot seem to access it with lodash sortBy. Is there a better way to approach this?

 example = () => {
   const exampleArray = [];


   _.forEach(this.state.example[name], (data) => {
       exampleArray.push({name, data });
   })

    // these logs all work fine
    console.log(exampleArray); 
    console.log(exampleArray[0]);
    console.log(exampleArray[0].data.count); // prints out 4

    //****console error: data is undefined
    _.sortBy(exampleArray, [name, data.count]);

    return exampleArray
}
  • Possible duplicate of [Lodash sort collection based on external array](https://stackoverflow.com/questions/28719795/lodash-sort-collection-based-on-external-array) – Roy Wang May 10 '18 at 17:03
  • not an external array. I'm trying to sort an array by a specific attribute which is contained inside yet another array object which is still contained into the overall array. – Jackson Miller May 10 '18 at 17:27

0 Answers0