0

I am working with jsPDF and have a variable joke and use .splitTextToSize to have it display nicely on the page.

var doc = new jsPDF()

var joke = "A Computer Science student at MIT showed up at his buddies dorm room with a new bike. His buddy said sweet bike, where’d ya get it? You’ll never believe this, he said, I was walking across campus and this beautiful blonde on a bike stopped, threw down her bike, tore off all her clothes and said _take whatever you want!_ His buddy stared at him blankly for a minute, then said smart. Her clothes would have never fit you.";

var line = doc.splitTextToSize(joke, 100)

doc.text(10,10, line)

The document now contains the following.

A Computer Science student at MIT 
showed up at his buddies dorm room  
with a new bike. His buddy said sweet 
bike, where’d ya get it? You’ll never 
believe this, he said, I was walking 
across campus and this beautiful 
blonde on a bike stopped, threw down 
her bike, tore off all her clothes and 
said _take whatever you want!_ 
His buddy stared at him blankly for a 
minute, then said smart. Her clothes 
would have never fit you.

Is there way to get the split var line and retrieve the last three line of the string? I was wondering if you can split by line number

His buddy stared at him blankly for a
minute, then said smart. Her clothes 
would have never fit you.
TecHunter
  • 6,091
  • 2
  • 30
  • 47
Paul Blart
  • 183
  • 1
  • 3
  • 12

1 Answers1

0

since it returns an array you can just :

var line = doc.splitTextToSize(joke, 100).slice(-3)

some reading you might find helpful: Destructuring to get the last element of an array in es6

TecHunter
  • 6,091
  • 2
  • 30
  • 47