I’m sure there are many ways to achieve that but I’m looking for something “elegant”.
JavaScript
x
16
16
1
a = [
2
'a',
3
'b',
4
'c'
5
];
6
7
magicArrayJoin(a, {value: 255} ); // insert the same object between each item
8
9
result == [
10
'a',
11
{value: 255},
12
'b',
13
{value: 255}
14
'c'
15
];
16
All proposals are welcome. 🙂
Advertisement
Answer
This worked for me:
JavaScript
1
2
1
a.map(val = [val, {value: 255}]).flat()
2