This may be a duplicate question. But I didn't find any similar questions in this forum.
I'm trying to modify values in an array to different format.
arrayInput = ['A', 'B', 'C', 'D', 'E', 'F'];
arrayOutput= ['A;B', 'C;D', 'E;F'];
I got the solution with the following approach
let arrayInput = ['A', 'B', 'C', 'D', 'E', 'F']
arrayOutput = [arrayInput[0]+';'+ arrayInput[1], arrayInput[2]+';'+ arrayInput[3]];
if (arrayInput[4]) {
let val = arrayInput[4] + (arrayInput[5] ? ';'+arrayInput[5] : '');
arrayOutput.push(val);
}
console.log(arrayOutput);
But I am looking for a generic solution such that even if I have more items in array, it should generate the output in desired format.
['A', 'B', 'C', 'D', 'E', 'F', 'G'] ==> ['A;B', 'C;D', 'E;F', 'G']
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'] ==> ['A;B', 'C;D', 'E;F', 'G;H']
Thanks for the support