Thanks for the other solutions
I make a new one:
function extractString(sperator, str, limit = -1) {
const parts = str.split(sperator);
if (parts.length <= limit) {
return parts;
}
return [
...parts.slice(0, limit - 1),
parts.slice(limit - 1, parts.length).join(';'),
];
}
const str = 'name;price;content ; content 2 ; content3';
console.log(extractString(';', str, 3));