I have an array of arrays that looks like this.
const data = [
['list1'],
['item1', '1'],
['item2', '2'],
['item3', '3'],
['item4', '4'],
[' ']
['list2'],
['item1', '1'],
['item2', '2'],
['item3', '3'],
['item4', '4'],
[' ']
['list3'],
['item1', '1'],
['item2', '2'],
['item3', '3'],
['item4', '4'],
[' ']
]
I need to get all of the items between the list1, list2 & list3 and the empty value to build a more structured container so that list1, list2 & list3 include the items as children. e.g. {
const data2 = {
'list1': {'item1': '1', 'item2': '2', 'item3': '3', 'item4': '4'},
'list2': {'item1': '1', 'item2': '2', 'item3': '3', 'item4': '4'},
'list3': {'item1': '1', 'item2': '2', 'item3': '3', 'item4': '4'},
'list4': {'item1': '1', 'item2': '2', 'item3': '3', 'item4': '4'}
}
Whats the most efficient way to query the data array to get the items between the list headers? I see lodash has a _.slice method which takes an index but I can't see a way to use the value of the array as a delimiter.