简体   繁体   中英

IONIC: How convert an Object array into array?

I'm trying to convert an Object array into an array without use "let item of array" on html, I already google a lot but nothing that I find works.

Why I don't use loops? because I pretend to display data inside a page that comes from a liteSQL database, so all the data that I extract from that it's an Object and sure I can display the data without issues if I use a loop like "let item of array" but in this case I just want to show information on the HTML like item.name or item.avatar

Thanks in advance for any help, If you guys need more information please let me know.

The database have students so every array have: name, age, avatar, etc, so I try to show some like a profile after they tap the name on the list

EDIT: 这是对象数组的样子

What you are receiving from your server is an array of objects.

array of objects ->

[{
  key1:vlaue1,
  key2:value2
 },
 {
  key1:vlaue1,
  key2:value2
 }]

You refer the values here by using array[0]['key1'] array[0]['key2'] and so on

In your case, you are receiving only one object in the array, so simply use array[0].name array[0].age and so on

Thanks for the help, I actually found the solution by my self, I just need to use:

item: array = <array>{};

in order to use my object array as a simple array items without any loop on html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM