I am trying to reduce an array of strings into individual strings, it works well only if i have one string within each array, but not more than one.
const listItems = [
{
sys: {
type: 'Link',
linkType: 'Entry',
id: 'm-list-basic-1'
}
},
{
sys: {
type: 'Link',
linkType: 'Entry',
id: 'm-list-basic-2'
}
},
{
sys: {
type: 'Link',
linkType: 'Entry',
id: 'm-list-basic-3'
}
}
];
const listIds = listItems.reduce((a, currentValue) =>
[...a, currentValue.sys.id], [])
// I have also tried `mlistId.toString()`
console.log(...listIds)
Currently i get, for example:
m-list-basic-1 m-list-basic-2 m-list-basic-3 (all on the same line using spread)
m-list-basic-1,m-list-basic-2,m-list-basic-3 (comma'ed using toString()
whereas i want them individual like so:
m-list-basic-1
m-list-basic-2
m-list-basic-3
maprather thanreduce). Can you show both the output you want to obtain, and what you actually get, so we can see the problem?