I want my code to concat a array with its index, using Join
x=['G','r','e','e','t']
x.join(${index}
)
then x should be G0r1e2e3t4
can I achieve this using join?
CodePudding user response:
['G','r','e','e','t'].map((e, i) => e i).join('')
CodePudding user response:
What about something like this:
const arr = ['G','r','e','e','t'];
const result = arr.reduce(
(accumulator, current, index) => accumulator current index,
[]
);
CodePudding user response:
console.log(
['G','r','e','e','t'].reduce((a,c,i)=>a c i,'')
)