Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Limiting characters in my description to 140 characters with javascript

I’m working on a project that requires a list of books to be printed onto the page using an api url.

Code works wonders, but I’m struggling to limit the characters to 140 for the description as requested.

function renderItemHtml(item) {
return `<div class="book"><img src="${item.volumeInfo.imageLinks.thumbnail}" class="thumbnails" 
alt="${item.singleTitle} by ${item.volumeInfo.authors[0]}" />
<div>
<h4>${item.volumeInfo.title}</h4>
<p><strong>${item.volumeInfo.authors}</strong></p>
<h8>${item.volumeInfo.description}</h8>        <-------- what i need to limit
</div>
<br>
<h8>Pages:  ${item.volumeInfo.pageCount}</h8>
</div>`

}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Just do this:

<h8>${item.volumeInfo.description.slice(0,140)}</h8> 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading