I have the following where it will display items in a certain way.
import './App.css'
import _ from 'lodash'
const App = () => {
const dataone = [
{ id: 1, month: 'jan', level: 8, clazz_id: '1A' },
{ id: 2, month: 'feb', level: 6, clazz_id: '1A' },
{ id: 3, month: 'jan', level: 2, clazz_id: '2B' },
{ id: 4, month: 'feb', level: 3, clazz_id: '2B' },
{ id: 5, month: 'mar', level: 5, clazz_id: '2B' },
]
const data = _.groupBy(dataone, 'clazz_id')
const entries = Object.entries(data)
return (
<div className='App'>
{entries.map((item, index) => (
<div>
<h2>{item[0]}</h2>
<h2>
{item[1].map((e) => (
<p>
{e.month}
{'--'}
{e.level}
</p>
))}
</h2>
</div>
))}
</div>
)
}
export default App
The above code will display the array of objects like below:
1A
jan-8
feb-6
2B
jan-2
feb-3
mar-5
This is what I want however the above code is done with lodash and object.entries and so I am looking for a better and clearner solution.