I have an array of <FilterGroup /> objects. I want to insert a <Conjunction />object after each <FilterGroup> object except the last one.
So the array should go from:
[
<FilterGroup />
<FilterGroup />
<FilterGroup />
<FilterGroup />
]
To:
[
<FilterGroup />
<Conjunction />
<FilterGroup />
<Conjunction />
<FilterGroup />
<Conjunction />
<FilterGroup />
]
My attempts so far have led me to:
filterGroups.filter(function(filterGroup, index) {
if(index !== filterGroups.length-1){
filterGroups.push(<Conjunction key={index} />);
}
})
I need to replace push() as it appends the element onto the end of the array.