I want to convert string to object array. Suppose I have following string.
const str = "someValue,display";
I want to convert it like following.
[{
columnVal: "someValue",
display: true
}]
if it's display then I want value as true if noDisplay then false.
I tried following but, to me it doesn't seems like best solution.
const val = "someValue,display";
const obj = {};
val.split(",").forEach((str, index) => {
if(index === 0) {
obj.columnVal = str;
} else {
if(str == "display") {
obj.display = true;
} else {
obj.display = false;
}
}
})
console.log([obj]);