0

I basically want to use the key as a variable.

I was able to get the object key (c000_01) however now I need to get the value of that object (Master).

I provided a snippet hopefully that helps

const data = [
          {
            "idx":"10100001",
            "name":"주인공",
            "skins":{
              "c000_01":"Master"
            },
          }
          ,{
            "idx":"10100002",
            "name":"모나",
            "skins":{
              "c001_17":"Petit Mona",
              "c001_01":"Mona",
              "c001_02":"Battlesuit Mona",
              "c001_16":"Swimsuit Mona"
            },
          }
          ,{
            "idx":"10100003",
            "name":"리자",
            "skins":{
              "c002_12":"Summer Camp Lisa",
              "c002_02":"Battlesuit Lisa",
              "c002_01":"Lisa",
              "c002_00":"Lisa"
            }
            }]
            
 for (i in data) {
    for (key in data[i].skins){
    console.log(key)
    }
  }

// what I wanted to do is

 for (i in data) {
    for (key in data[i].skins){
    
    console.log(data[i].skins.key) //I want the key to be an variable so i can get the value to show master, petit mona, mona, battle suit mona, etc etc etc)
    console.log(data[i].skins.c000_01) // I don't want to type in c000_01, I want to use the key instead
    
    }
  }

1 Answers1

0
 for (i in data) {
    for (key in data[i].skins){
    console.log(data[i].skins[key])//<-----this is what you want
    }
  }
shenzhigang
  • 103
  • 8