Answer the question
In order to leave comments, you need to log in
How can I get a variable out of the database or store a JSON variable declared in a file?
Good afternoon, how can I write a variable into a JSON object and then display it. If the variable is declared in a file.
Example, implementation, how it should look like
"shop": {
"Gift-1": { "id": 1, "title": "Подарок 1", "price": 250, "data": dataList1 },
"Gift-2": { "id": 2, "title": "Подарок 2", "price": 500, "data": dataList2 },
"Gift-3": { "id": 3, "title": "Подарок 3", "price": 550, "data": dataList3 },
"Gift-4": { "id": 4, "title": "Подарок 4", "price": 1000, "data": dataList4 },
"Gift-5": { "id": 5, "title": "Подарок 5", "price": 1500, "data": dataList5 },
"Gift-6": { "id": 6, "title": "Подарок 6", "price": 3000, "data": dataList6 }
}
for(let key in shop){
console.log( shop[key].title + ' ' + shop[key].price + ' ' + shop[key].data)
}
Answer the question
In order to leave comments, you need to log in
<script id="myJson" type="application/json">
{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
}
</script>
let json = document.querySelector('#myJson');
let obj = JSON.parse(json.innerHTML);
console.log(obj);
fetch('https://jsonplaceholder.typicode.com/todos/1').then(res => res.json()).then(data => console.log(data))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question