How to access javascript object

1

Hello, I have this javascript code:

require("TimeSlice").guard(function() {
    (require("ServerJSDefine")).handleDefines([["cr:692209", ["cancelIdleCallbackBlue"], {
        "__rc": ["cancelIdleCallbackBlue", null]
    }
    , 3419], ["DTSGInitData", [], {
        "token": "987654321", "async_get_token": "123456789"
    }
}

 ]
 ]
 )
)

I would like to access the value of async_get_token osea 123456789 Any idea how to achieve this?

I tried this

console.log(array[2].async_get_token);
    
asked by Rafael Dorado 03.01.2019 в 20:56
source

2 answers

1

Since your source is an array , you should only get the property within the item of that array; keep in mind that the items in the arrays start with the 0 position , so if you apply to your code the value is obtained like this

function obtener(){
  var data = ["DTSGInitData", [], { "token": "987654321", "async_get_token": "123456789" }, 3515];
  alert(data[2].async_get_token);
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>

<div class="container">
  <button type="button" class="btn btn-primary" onclick="obtener()">Obtener valor</button>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    
answered by 03.01.2019 в 21:08
1

You can achieve it this way:

let datos = ["DTSGInitData", [], {
    "token": "987654321", "async_get_token": "123456789"
}
, 3515]

console.log(datos[2]["async_get_token"])

EXPLANATION

  • Inside your main array, the object you want to read is in position 2, then indicate that the variable accesses position 2 and then the key "async_get_token"
answered by 03.01.2019 в 21:09