I have a string with special characters, I have to modify to array of object using javascript
so in a string, always before underscore considered as name
and after underscore is considered as type
- if semicolon is present, then can be two diff objects
tried
var arr = str2.split(';');
var result = arr.find( e => {
e.split(/[_,]/);
}).map(i => ({
name: i[0],
type: i.shift()
}));
var str1 = "xyz_dell,asus";
var str2 = "abc_new;red_old;zen_sg,my"
Expected Output for str1
[
{name: xyz, type: dell,asus}
]
Expected Output for str2
[
{name: abc, type: new},
{name: red, type: old},
{name: zen, type: sg, my}
]