jquery - Javascript Get Key from data (not showing key) -


i have data looks this:

var mydata =[{     "493":{         "name":"name 1",         "subhere":{             "subhere1":2         }     },     "673":{         "name":"name 2",         "subhere":{             "subhere1":20         }     } }]; 

i want keys value variable i’ve done this:

var data = []; (var = 0; < mydata.length; i++) {            var obj = mydata[i];          for(var key in obj){         var newobj = {                   name: obj[key].name,             y: obj[key].subhere.subhere1,             id: i,             test: obj[key]            };         data.push(newobj);           } } 

if @ line has test: obj[key] that’s line want value of key when console.log(this.test) object { name="name 1",…etc it’s not giving me 493 or 673

how can key number?

if @ line has “test: obj[key]” that’s line want value of key when console.log(this.test) “object { name=“name 1”,…etc” it’s not giving me “493” or “673”

simply replace

  test: obj[key]    

with

   test: key 

since having key in variable key


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -