Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
how to inject last 2 elements of an array into html

I'm creating a book store for a project due in the next few days.

I need to inject 10 elements from an array into the html, 8 of them into 1 section and the last 2 in a 'featured' section.

My current JS file is printing the correct stuff into my html, but i'm having trouble getting the last 2 injected into the featured section.

fetch('https://www.googleapis.com/books/v1/volumes?q=HTML5')
    .then(response => response.json())
    .then(data => console.log(data));

function handleResponse(obj) {
    obj.items.forEach((item, index) => {
        if (index > 7) return; // returns 8 elements from array
        let div = document.createElement('div');
        div.className = 'books';
        div.innerHTML = `<img src="${item.volumeInfo.imageLinks.thumbnail}" class="thumbnails" alt="${item.singleTitle} by ${item.volumeInfo.authors[0]}" />
            <h4>${item.volumeInfo.title}</h1>
            <p><strong>${item.volumeInfo.authors}</strong></p>
            <h8>${item.volumeInfo.description}</h8>
            <br>
            <br>
            <h8>Pages:  ${item.volumeInfo.pageCount}</h8>`

        let container = document.querySelector('.booklist-cards');
        container.append(div);
    })
}

The code where I would like to inject the last 2 into my html is

<div>
    <div>
        <div class="booklist-featured">
            <h1>Featured</h1>
            <div class="booklist-featured">
                book1
            </div>
            <div class="booklist-featured">
                book2
            </div>
        </div>
    </div>
</div

I also need to limit the description to 140 characters.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!