0

I Have an array named 'treeArray':

Array[78]
 0
 *function:Object
 *menu :
       id:1
       id_parent:1
       name:"Settings"
 1
 *function:Object
 *menu:
       id:1
       id_parent:1
       name:"Settings"      

 2
 *function:Object
 *menu:
       id:1
       id_parent:2
       name:"game"

I would like to get two arrays : The first one would contain Objects which follows :

 menu.id=menu.id_parent

and the second one where

menu.id!=menu.id_parent

How can i achieve this with lodash ? Thank you

John
  • 185
  • 1
  • 6
  • 21
  • Please read [ask]. Key phrases: "Search, and research" and "Explain ... any difficulties that have prevented you from solving it yourself". – Heretic Monkey Dec 20 '16 at 17:30

1 Answers1

1

use _.partition like

_.partition(treeArray, function(item) {
    return item.menu.id === item.menu.id_parent;
})

it returns [[...truthly items...], [...falsy items...]]

stasovlas
  • 7,136
  • 2
  • 28
  • 29