Answers for "js combine array into string without last element"

2

join last element of array javascript with different value

['tom', 'dick', 'harry'].join(', ').replace(/, ([^,]*)$/, ' and $1')
> "tom, dick and harry"
Posted by: Guest on September-09-2020
0

javascript array join last element with and

var a = ['a', 'b', 'c'];
var str = a.slice(0, -1).join(',')+' or '+a.slice(-1);
Posted by: Guest on February-26-2022

Code answers related to "js combine array into string without last element"

Code answers related to "Javascript"

Browse Popular Code Answers by Language