Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
32
rated 0 times [  36] [ 4]  / answers: 1 / hits: 18337  / 9 Years ago, fri, august 7, 2015, 12:00:00

I'm sure there are many ways to achieve that but I'm looking for something elegant.



a = [
'a',
'b',
'c'
];

magicArrayJoin(a, {value: 255} ); // insert the same object between each item

result == [
'a',
{value: 255},
'b',
{value: 255}
'c'
];


All proposals are welcome. :)


More From » arrays

 Answers
5

This worked for me:


 a.map(val = [val, {value: 255}]).flat()

[#65497] Thursday, August 6, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryley

Total Points: 118
Total Questions: 81
Total Answers: 102

Location: Kazakhstan
Member since Thu, Dec 23, 2021
2 Years ago
;