Tag: JavaScript
-
How to display a JavaScript array in HTML
From time to time, I see a search query that made it to my blog that piques my interest and inspires a post. This is one such post. How does one take an array (presumably in JavaScript) and display it in HTML? Now in this day in age, I would…
-
Splitting strings and keeping the separator in JavaScript
When splitting strings, the majority of the time, I don’t care about the separator (or delimiter), just the strings that exist between it. In JavaScript, that’s very simply with .split(): ‘one,two,three,four,five’.split(‘,’); Which will yield an array of strings like this: [‘one’, ‘two’, ‘three’, ‘four’, ‘five’] Great! But if we want…
-
Repeating Strings in JavaScript
While cleaning up some of my old notes today, specifically stuff I jotted down that would make for a good blog topic, I happened upon the topic of repeating strings in JavaScript. Things are really easy in ES6+, but if you happen to still support Internet Explorer for some crazy…
-
Overengineering Challenge: Is Number Even or Odd in JavaScript
Code golfing is fun, and makes for great blog posts. The problem is, the world is flooded with posts attempting to show you how to write the best / most concise code imaginable. With that, I decided that it would be a fun challenge to attempt to take a simple…
-
How to set the background color of a Google Chart
As luck would have it a Google Chart I had created some time last year, which was looking great for a while, recently decided that the background color of the chart itself was going to switch from the color I had set to the default color, white. This was quite…
-
Recursive functions in TypeScript
In working with the Slate framework for building rich text editors recently, I found myself faced with a scenario where I needed to loop through the editor’s value. The value that comes out the editor is an array of objects that is nestable, I assume infinitely, by way of the…
-
Error: Cannot resolve a DOM point from Slate point
By way of recommendation (thanks Brewer), I’ve been messing around with Slate.js a ton. Such is life, I did have my fair share of issues, particularly in terms of getting it to function like a chat message input where hitting Enter will submit the form and reset it to it’s…
-
Resetting a Slate.js editor to an empty state
I’ve been messing with Slate.js and happen to be using it in the context of having a persistent editor on the page that can be used post from. It’s sort of like a chat’s message input, it’s always there, and when you submit it, it resets back to it’s original…
-
Resetting the undo/redo history of a Slate.js editor
Slate.js has some wonderful undo/redo history under the hood, by way of the React hook useMemo. Out of the box is works great, but if you want to reset your editor back to an empty state (in scenarios where the component is persistent on the page), the undo/redo history will…
-
Submit on enter except when shift is pressed in JavaScript
Been working on something recently where I wanted to implement a submit handler when a user hits the enter key in an input. That’s not that big of a deal, sniff out the key being pressed, and if it’s the Enter key, go ahead and execute the submit handler. Since…