join method code example
Example 1: join last element of array javascript with different value
['tom', 'dick', 'harry'].join(', ').replace(/, ([^,]*)$/, ' and $1')
> "tom, dick and harry"
Example 2: javascript array to comma separated string
var colors = ["red", "blue", "green"];
var colorsCSV = colors.join(","); //"red,blue,green"
Example 3: Concatenate Item in list to strings
>>> sentence = ['this','is','a','sentence']
>>> '-'.join(sentence)
'this-is-a-sentence'
Example 4: .join in javascript
const elements = ['Sun', 'Earth', 'Moon'];
console.log(elements.join());
// output: "Sun,Earth,Moon"
console.log(elements.join(''));
// output: "SunEarthMoon"
console.log(elements.join('-'));
// output: "Sun-Earth-Moon"
Example 5: join method in python
flowers = [
"Daffodil",
"Evening Primrose",
"Hydrangea",
"Iris",
"Lavender",
"Sunflower",
"Tiger Lilly",
]
print(", ".join(flowers))
Example 6: join function in python
"seperator".join(list/tuple)