像这样转换json对象的最佳方法是什么?
{"id" : 1, "name": "John"}
到json数组
[{"id" : 1},{"name": "John"}]
使用javascript。
更新:我想这样做,因为在Sequelize中,必须在Json中使用操作符“或”将过滤器作为Json数组传递。
你可以做
let obj = {"id" : 1, "name": "John"};
let result = Object.keys(obj).map(e => {
let ret = {};
ret[e] = obj[e];
return ret;
});
console.log(result);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句