I'm using react.js for building my dashboard
I want to convert an array like this (old version) [ {...}, {...}, {...} ] into this (new version) {...}, {...}, {...} in javascript
So I can put the new version of the array inside a JSON array like this [ {...}, newArray ]
I know a map function returns an array and I know it's a silly question but I wonder how
here is my code:
const siteProfilesList = ['ABC', 'DEF', 'GHI']
const pagesList = ['Dashboard', 'Routes', 'Payload']
const siteProfileNavigationsList = siteProfilesList.map((item, index) => {
let menu = {}
menu['_tag'] = 'CSidebarNavDropdown'
menu['name'] = item
menu['_children'] = pagesList.map((pageItem, pageIndex) => {
let pageMenu = {}
pageMenu['_tag'] = 'CSidebarNavItem'
pageMenu['name'] = pageItem
pageMenu['to'] = `/${pageItem.toLowerCase()}/location=${item.toLowerCase()}`
return pageMenu
})
return menu
})
const navigations = [
{
_tag: 'CSidebarNavTitle',
_children: ['Site Profile']
},
siteProfileNavigationsList
]
export default navigations
I know it's a silly question but I just wonder about the solution.