I have a function where I get the following array:
var result = ["a-x-y", "b+x+y", "b+x+y", "b+x+y", "c_x_y", "c_x_y", "d_x_y"];
As a result, however, I would only like to receive the string with the attached special character and the number of occurrences only once:
var result = ["a-x-y~1", "b+x+y~3", "c_x_y~2", "d_x_y~1"]
Here the function:
var folders = ["a-x-y_1", "b+x+y_1", "b+x+y_3", "b+x+y_2", "c_x_y_1", "c_x_y_2", "d_x_y_1"];
folders.forEach(function (item) {
var index = item.lastIndexOf("_");
var result = item.substring(0, index);
console.log(result);
});