I am mapping an array of object in react. The array is as follows
const tabs = [
{
index: 0,
title: 'v1',
path: '/v1',
component: versionManager,
},
{
index: 1,
title: 'v2',
path: '/v2',
component: version2Manager,
},
{
index: 0,
title: 'v3',
path: '/v3',
component: version3Manager,
},
];
I have successfully mapped the entire array with this
{tabs.map((item) => {
if (auth.verify(Roles.role1)) {
return (
<Tab
label={item.title}
key={item.index}
component={Link}
to={item.path}
/>
);
but I would like to add an else that only maps the first object (v1) and all of its elements, something similar to this.
} else {
return (
<Tab
label={item.title}
key={item.index}
component={Link}
to={item.path}
/>
)
}
I have tried thing such as item.title[0], item.index[0] ,etc.... but it gives an undefined error every time. Does anyone know the best way to only map the first object in the else statement? Thanks in advance.
I have seen Get first object from array of objects in react but this didn't seem to be helpful in my case.