Answer the question
In order to leave comments, you need to log in
How to get element from json javascript?
Conditionally code like this:
const tmp = '{ "qwerty": "1234567890" }';
console.log(JSON.parse(tmp).qwerty); // OK --- 1234567890
// Но если id будет хранится в переменной
var id = 'qwerty';
console.log(JSON.parse(tmp).id); // undefined
Answer the question
In order to leave comments, you need to log in
const tmp = '{ "qwerty": "1234567890" }';
console.log(JSON.parse(tmp).qwerty); // OK --- 1234567890
// Потому что синтаксис другой
var id = 'qwerty';
console.log(JSON.parse(tmp)[id]); // OK --- 1234567890
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question