I have an array [a, b, c]. I want to be able to insert a value between each elements of this array like that: [0, a, 0, b, 0, c, 0].
[a, b, c]
[0, a, 0, b, 0, c, 0]
I gues
Another way is to use some functional methods like zip and flat. Check out lodash.
const array = ['a', 'b', 'c'] const zeros = Array(array.length + 1).fill(0) const result = _.zip(zeros, array).flat().filter(x => x !== undefined) console.log(result)