I have an array of strings and want to join the string based on a condition. So if two elements comes then it should add & in between. Using array.join I am able to achieve.
But when array of string has more than two, one condition will be last two items will be having & joined
let data1 = ["orange"]
console.log(data1.join(" & ")) // correct
let data2 = ["orange", "apple"]
console.log(data2.join(" & ")) // correct
let data3 = ["orange", "apple", "mango"]
console.log(data3.join(" & ")) // wrong => orange, apple & mango
let data4 = ["orange", "apple", "mango", "guava"]
console.log(data4.join(" & ")) // wrong => orange, apple, mango & guava
How can I add custom logic on joining the strings, I have added the expected string on data3 and data4