I have an array like this.
var arr = [
{
Id:1533248,
Name:"HP",
ParentId:33113319,
ParentName:"Brand Name"
},
{
Id:1533764,
Name:"Samsung",
ParentId:33113319,
ParentName:"Brand Name"
}
]
And a template.
var template = 'a_{ParentName}:{ParentId}_({Name}:{Id})*'
I am trying to generate a string from template. All i have is the array of objects. Also section inside () can be repeated and separated by pipe.
This is the desired output.
var result = 'a_brand-name:33113319_hp:1533248|samsung:1533764|sony:1533438';
There could be many objects in array with same ParentId. I am trying to use regular expression but failing. I am no good at regular expressions.
Please help.