This is the string Option 1|false|Option 2|false|Option 3|false|Option 4|true I want to convert it to array of objects like this
Is This Possible In javaScript Nodejs???? thanks in Advance.
[
{
"option": "Option 1",
"value": false
},
{
"option": "Option 2",
"value": false
},
{
"option": "Option 3",
"value": false
},
{
"option": "Option 4",
"value": true
}
]
const result = "Option 1|false|Option 2|false|Option 3|false|Option 4|true".split('|').map((option, i, a) => i % 2 ? null : {option, value: a[i+1]}).filter(x => x)