如何将PostgreSQL中的数组,例如
我尝试过使用replace和split解决,但它返回字符串值。
"{1,2,3,4}"
转换为JavaScript/TypeScript数组:[1,2,3,4]
。 数组中的值必须是数字类型。我尝试过使用replace和split解决,但它返回字符串值。
var test = "{1,2,3,4}";
test = test.replace("{", "");
test = test.replace("}", "");
//test = test.replace(/\{|\}/gm, "") //regex replace
test.split(",") //['1', '2', '3', '4']
JSON.parse(test.replace("{", "[").replace("}", "]"))
- shajji