

Wide browser support: Edge, IE11, Firefox, Chrome, Safari, Opera, most mobile browsers.All styling is done through CSS, with sensible class names rather than ugly, namespaced, abbreviated nonsense.

The only thing you need is a good understanding of regular expressions. Multiple hooks are scattered throughout the source.

In addition, the language is defined through the way recommended in the HTML5 draft: through a language-xxxx class. On its own for inline code, or inside a for blocks of code. Prism forces you to use the correct element for marking up code. Other highlighters encourage or even force you to use elements that are semantically wrong, Each language definition adds roughly 300-500 bytes. If you’re still not sold, you can view more examples or try it out for yourself. This page’s logo (SVG), highlighted with Prism: This page’s HTML, highlighted with Prism: This page’s CSS code, highlighted with Prism: names.The Prism source, highlighted with Prism (don’t you just love how meta this is?): The setTimeout() method sets a timer which executes a function or specified piece of code once the timer expires. We could try slowing it down by adding a simple setTimeout(). The problem is that the browser loops over the array so quickly, that only our last element is shown. We can loop over the array and call display() on each name. The forEach() method executes a provided function once for each array element. To loop over this array and display each name, we can use (). Text can be displayed on the page by calling display("Hello World"). const output = document.querySelector( "#output") Ĭonst display = s = > output.innerText = s įirst, let’s create a function which displays text in this. I want to loop through an array of strings and display one string at a time on the page. Keep reading and we’ll build it together.

This functionality isn’t built in to JavaScript and I couldn’t find any libraries that provided it out-of-the-box. I recently ran into the problem of having to loop over an array, but with a delay between iterations.
