I love to code and JavaScript is my favourite flavour!
I'm adding a simple way to create a page break in Tiptap. It's not a full paged display, but it allows users to force a page break before a heading or at the end of a chapter.
Written by Codemzy in JavaScript on November 8th, 2024
Here's a JavaScript function I built to create a random 4-digit OTP code with leading zeros. And how I extended it to create shorter and longer codes too!
Written by Codemzy in JavaScript on July 3rd, 2024
When you use the JavaScript Fetch API, `response.body` might not work like you hoped it would. So if you run into errors like "Cannot read properties of undefined (reading 'body')", this blog post will help you fix it!
Written by Codemzy in JavaScript on April 11th, 2024
You can access response headers in axios from the response per request, or by adding an interceptor to all requests. If the headers are missing or undefined, you might need to fix your CORS settings.
Written by Codemzy in JavaScript on January 31st, 2024
Drag and drop can be a little tricky to implement. Here are some common problems you might run into and how to fix them to get your drag-and-drop working like a charm.
Written by Codemzy in JavaScript on October 25th, 2023
Both throttling and debouncing are useful ways to slow down how often a function runs when it's called multiple times. Throttling allows a function to be called once during a timeframe, and debouncing calls a function once after the timeframe.
Written by Codemzy in JavaScript on October 6th, 2023
In this blog post, we will create a `toPlural` function that does slightly more than just add an "s" to the end of a word if the number is more than one!
Written by Codemzy in JavaScript on October 5th, 2023
JavaScript converts values to true or false booleans in some contexts - like conditionals. A value that converts to true is a truthy, and one that converts to false is a falsy.
Written by Codemzy in JavaScript on September 21st, 2023
One of the hardest parts of coding is when something just doesn’t work. And you don’t know why. In this blog post, I'll show you 6 ways to figure out why your code isn't working.
Written by Codemzy in JavaScript on July 27th, 2023
In this blog post, I shuffle an array of objects into a random order with two JavaScript methods, `Array.sort()` and a `shuffleArray` function. Check out the code and which performs best.
Written by Codemzy in JavaScript on July 20th, 2023
Getting "[object Object]" is not valid JSON error in your code is annoying, but there is often a simple fix. Maybe you don't need JSON.parse(), or maybe you're giving it the wrong data. Here's an easy fix (and how to troubleshoot if you're still stuck).
Written by Codemzy in JavaScript on June 20th, 2023
You can use Array.join() on an array of objects, but `join()` will only work with strings, so you need to get the property value(s) first. Let's look at some examples.
Written by Codemzy in JavaScript on May 30th, 2023
In this blog post, I create a javascript function to separate the last word in a string, so I can keep it attached to an inline icon, to prevent the icon from wrapping to a new line on its own.
Written by Codemzy in JavaScript on May 25th, 2023
You can sort any array of objects in JavaScript using the `sort()` method and giving it a compare function with the property value you want to sort by. Here's how it works with examples.
Written by Codemzy in JavaScript on May 22nd, 2023
Need to be able to drag and drop image files into your Tiptap WYSIWYG editor? Tiptap is highly customisable, so let's add some drag-and-drop magic to the Image extension.
Written by Codemzy in JavaScript on January 27th, 2023
If you need a simple short ID and don't have any complex requirements for it, then a simple JavaScript function could be all you need. Here's the function I use to create a random unique ID in JavaScript, and an explanation of how it works.
Written by Codemzy in JavaScript on January 13th, 2023
Looping over arrays is fairly easy in JavaScript, but harder with objects, because you can't use array functions like `Array.map()`. Or can you?
Written by Codemzy in JavaScript on August 24th, 2022
Here's the conditional object property pattern. It uses the spread syntax (...) to conditionally add a property to an object, or an item to an array. Perfect when you (sometimes) want to add a key to an object.
Written by Codemzy in JavaScript on August 15th, 2022
Copying objects in javascript can get complicated if you only want to copy part of an object, or if there is a property or key that you don't need. Instead of copying the entire object and then deleting a property, you can just copy what you need with object destructuring.
Written by Codemzy in JavaScript on July 27th, 2022