How can I retrieve a new variable (section) after every 3 objects are called from an array in JavaScript ES6 Map? I've attempted to do this with an ES6 Map, but I'm not achieving the desired result. Can someone please assist me? Thank you! Below is my code:
const array = [
{
id:1,
name:'naren'
},
{
id:2,
name:'naren2'
},
{
id:3,
name:'naren3'
},
{
id:4,
name:'naren4'
},
{
id:5,
name:'naren5'
},
{
id:6,
name:'naren6'
},
{
id:7,
name:'naren7'
}
{
id:8,
name:'naren8'
}
]
//New Section
const section = 'New section';
Expected Output Result in console
Output:
naren1
naren2
naren3
New Section
naren4
naren5
naren6
naren7
naren8