angular - TypeScript:Undefined value when get value in table -


how can value of table in typescript, ? result of console.log(jsonusers)

mycomponent.ts :

let jsonusers = []; getuser() {  // when console ==> response on picture  console.log(this.jsonusers );  // want value of code , label not worked   console.log(jsonusers.length); // ==> 0  (var index = 0; index < this.jsonusers .length; index++) {       var element = this.jsonusers [0];       console.log(element.code);  } 

mycode

looks array has no elements on it, see in console's output object's keys. try this, , let know see

let jsonusers = []; getuser() {     const keys = object.keys(this.jsonusers);     keys.foreach((k, i) => {         const element = this.jsonusers[k];         console.log(element.code)     }) } 

or option using for...in

let jsonusers = []; getuser() {     (let k in this.jsonusers) {         const element = this.jsonusers[k];         console.log(element.code)     } } 

note this.jsonusers different variable jsonusers, keep in mind


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -