JSFiddle - React, Tailwind, and code Playground

by Abdul Ahmad

JavaScript

const objectify = getAllData().reduce((acc, item) => {
	if (!acc[item.chapterId]) acc[item.chapterId] = [item.name];
  else acc[item.chapterId].push(item.name);
  return acc;
}, {});
console.log(objectify);



function getAllData() {
	return [
  	{
        'name': 'Other viral diseases (B25-B34)',
        'chapterId': 1,
        'sectionId': 15
    },
    {
        'name': 'Mycoses (B35-B49)',
        'chapterId': 1,
        'sectionId': 16
    },
    {
        'name': 'Protozoal diseases (B50-B64)',
        'chapterId': 1,
        'sectionId': 17
    },
    {
        'name': 'Helminthiases (B65-B83)',
        'chapterId': 1,
        'sectionId': 18
    },
    {
        'name': 'Pediculosis, acariasis and other infestations (B85-B89)',
        'chapterId': 1,
        'sectionId': 19
    },
    {
        'name': 'Sequelae of infectious and parasitic diseases (B90-B94)',
        'chapterId': 1,
        'sectionId': 20
    },
    {
        'name': 'Bacterial and viral infectious agents (B95-B97)',
        'chapterId': 1,
        'sectionId': 21
    },
    {
        'name': 'Other infectious diseases (B99)',
        'chapterId': 1,
        'sectionId': 22
    },
    {
        'name': 'Malignant neoplasms of lip, oral cavity and pharynx (C00-C14)',
        'chapterId': 2,
        'sectionId': 25
    },
    {
        'name': 'Malignant neoplasms of digestive organs (C15-C26)',
        'chapterId': 2,
        'sectionId': 26
    },
    {
        'name': 'Malignant neoplasms of respiratory and intrathoracic organs (C30-C39)',
        'chapterId': 2,
        'sectionId': 27
    },
    {
        'name': 'Malignant neoplasms of bone and articular cartilage (C40-C41)',
        'chapterId': 2,
        'sectionId': 28
    },
    {
        'name': 'Melanoma and other malignant neoplasms of skin (C43-C44)',
        'chapterId': 2,
        'sectionId': 29
    },
    {
        'name': 'Malignant neoplasms of mesothelial and soft tissue (C45-C49)',
        'chapterId': 2,
       ...