• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Archives for Miscellaneous

Miscellaneous

Convert a string to an array of characters

Convert a string to an array of characters

Use the spread operator (…) to convert the string into an array of characters. Source https://www.30secondsofcode.org/js/s/to-char-array

Miscellaneous

Vanilla JS toggle

Vanilla JS toggle

Source https://github.com/roeib/JavaScript-snippets#vanilla-js-toggle

Miscellaneous

Get an array of key/value pairs from an object

Get an array of key/value pairs from an object

Return an array of key/value pairs, also represented as arrays. Pass in the object as an argument. Source https://vanillajstoolkit.com/reference/objects/object-entries/

Miscellaneous

What is the difference between prefix and postfix operators?

What is the difference between prefix and postfix operators?

The increment operator (++) adds 1 to its operand and returns a value. Similarly, the decrement operator (–) subtracts 1 from its operand and returns a value. Both of these operators can be used either prefix (++i, –i) or postfix (i++, i–). If used prefix, the value is incremented/decremented, and the value of the expression is the updated value. If used […]

Miscellaneous

Fire an event listener only once

Fire an event listener only once

Source https://github.com/roeib/JavaScript-snippets#fire-an-event-listener-only-once

Miscellaneous

Return an array of keys from an object

Return an array of keys from an object

Return an array of keys from an object. Pass in the object as an argument. Source https://vanillajstoolkit.com/reference/objects/object-keys/

Miscellaneous

Get the index of the first matching item in an array

Get the index of the first matching item in an array

Get the index of the first matching item in an array. Returns -1 if no matching item is found. Source https://vanillajstoolkit.com/reference/arrays/array-indexof.md/

Miscellaneous

Sorting by an Object Property

Sorting by an Object Property

You can sort arrays of objects. In this case we leverage the collator.compare method and pass along the properties that we want to sort by. Source https://elijahmanor.com/byte/js-locale-sort

Miscellaneous

Add special characters to text to print in color in the console

Add special characters to text to print in color in the console

This code adds special characters to text to print in color in the console (combined with console.log()). Use template literals and special characters to add the appropriate color code to the string output. For background colors, add a special character that resets the background color at the end of the string. Source https://www.30secondsofcode.org/js/s/colorize

Miscellaneous

Tell the browser when to run your JavaScript code

Tell the browser when to run your JavaScript code

In HTML5, you can tell the browser when to run your JavaScript code. Source https://github.com/roeib/JavaScript-snippets#in-html5-you-can-tell-the-browser-when-to-run-your-javascript-code

Miscellaneous

  • « Go to Previous Page
  • Go to page 1
  • Interim pages omitted …
  • Go to page 4
  • Go to page 5
  • Go to page 6
  • Go to page 7
  • Go to page 8
  • Interim pages omitted …
  • Go to page 16
  • Go to Next Page »

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers