1👍
You can convert this string to Array, create a new function to parse the string and return it using Function constructor, but this will create an Array with undefined Objects:
function looseJsonParse(obj){
return Function('"use strict";return (' + obj + ')')();
}
const str = "[,,3,,]";
const DataArray = looseJsonParse(str);
console.log(DataArray);
you can simply .filter()
the elements if you want just only valid values in your data array:
function looseJsonParse(obj){
return Function('"use strict";return (' + obj + ')')();
}
const str = "[,,3,,]";
const DataArray = looseJsonParse(str).filter(el => el);
console.log(DataArray);
Source:stackexchange.com