angular - TypeScript:Undefined value when get value in table -
how can value of table in typescript, ?
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); }
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
Post a Comment