Array Inject

Today I had to create a function which added one element after every single element in an array. E.g.
['a', 'a', 'a'] => ['a', 'b', 'a', 'b', 'a', 'b']

Because of the nice array methods like map, and filter and such I searched for a similar method for injecting elements accepting an arrow function but I couldn't find one. I thought an inject method might be a nice addition following this pattern:
[1,2,3].inject(el => el > 2, el => el += 2);

The first parameter being a boolean function to see where to inject a new element, and the second parameter being or returning a value to inject in that position giving the result:
[1,2,3,5,4,6]

Like map it wouldn't mutate the original array but instead return a new one.
I'd like to hear what other people think of this idea.

Hello Roy!

The more generic abstraction over map and filter would be flatMap. With that, you can easily achieve the results you're looking for:

['a', 'a', 'a'].flatMap(x => [x, 'b'])

[1,2,3,4].flatMap(el => el>2 ? [el, el+2] : [el])

Oh cool, I didn't know flatMap was used for this, i will rewrite my function using this method thank you!

while(element = array.pop()){
      array0.push(element)
      array0.push(elementAfterEachElementInArray)
}