How to convert object to array by javascript / angular

the extracted api format is pure object format

{"name":"james","city":"Taipei","country":"Taiwan"}

using ngFor to run the table cannot run out because object format is not supported

how do I change it to array format?

want to become

[
    {"name":"james","city":"Taipei","country":"Taiwan"}
]

Dec.15,2021

although data can be processed directly in Component or Directive, a more orthodox approach would be to implement a pipe , such as

import { PipeTransform, Pipe } from '@angular/core';

@Pipe({name: 'keys'})
export class KeysPipe implements PipeTransform {
  transform(value, args:string[]) : any {
    let keys = [];
    for (let key in value) {
      keys.push(key);
    }
    return keys;
  }
}

after

*ngFor="let key of obj | keys"

similarly, you can also implement the tuple format of [key, value]

.

[] .push ({"name": "james", "city": "Taipei", "country": "Taiwan"}) is not OK?


let o = {"name":"james","city":"Taipei","country":"Taiwan"}
let arr = [o]

what's the point of turning this array into such an array?

if you want to traverse an object, you can use for. In. or use Object.keys () and Object.values ()

in es6 .
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c416-4d999.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c416-4d999.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?