Задать вопрос
Ответы пользователя по тегу JSON
  • Как вытащить все значения из json через key?

    vool
    @vool
    Разработчик
    Вот код чтобы вывести ваши елементы:
    async function getResponse() {
        let response = await fetch('https://dummyjson.com/products') 
        let jsonList = await response.json()
        let list = document.querySelector('.products')
        let key
        let elements = jsonList.products
        elements = elements.splice(0, 3)
    
        for (key of elements) {
            list.innerHTML += 
            `<li class="item">
                <h5 class="small_panel">${key.title}</h5>
                    <div class="full_panel">
                        <img src="${key.thumbnail}" alt="${key.description}"></img>
                        <p>brand: ${key.brand}</p>
                        <p>category: ${key.category}</p>
                        <p>${key.description}</p>
                        <p>discount percentage: ${key.discountPercentage} %</p>
                        <p>price: ${key.price} usd</p>
                        <p>rating: ${key.rating}</p>
                        <p>stock: ${key.stock}</p>
                </div>
            </li>`
        }
    }
    
    
    getResponse()
    Ответ написан