[英]How to Convert Object to Array of Object? in Angular
I have a problem in my code, the problem is I want to convert an object to an array, but according to the example below for the object can be seen in the image link.我的代码有问题,问题是我想将对象转换为数组,但是根据下面的示例,可以在图像链接中看到对象。
https://i.imgur.com/j5wDhNQ.png (the object output) https://i.imgur.com/j5wDhNQ.png (对象输出)
example:例子:
{ [ 0:{"name": "fiqih", "diskusi": 5} 1:{"name": "Nah", "diskusi": 2} 2:{"name": "Nah2", "diskusi": 4} etc.. ] }
Just place your object in an array or use new Array()
like below只需将您的对象放在一个数组中或使用如下所示的
new Array()
const obj = {foo: 'bar'}; const arr = [obj]; // or new Array(obj); console.log(arr);
You can do like this:你可以这样做:
var obj= {"1": 1, "2": 2}
var arr = Object.entries(obj)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.