• 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

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

Combine all items in an array into a string

Combine all items in an array into a string

Combine all items in an array into a string, separated by a delimiter that you can pass in as an argument. By default, it will use a comma (,) as the delimiter if one is not provided. Source https://vanillajstoolkit.com/reference/arrays/array-join/

Miscellaneous

Count the occurrences of a value in an array

Count the occurrences of a value in an array

Use Array.prototype.reduce() to increment a counter each time the specific value is encountered inside the array. Source https://www.30secondsofcode.org/js/s/count-occurrences

Miscellaneous

Capture the right click event with JavaScript

Capture the right click event with JavaScript

Two ways to capture the right click on a mouse.

Miscellaneous

Reverse the order of items in an array

Reverse the order of items in an array

Reverse the order of items in an array. Source https://vanillajstoolkit.com/reference/arrays/array-reverse/

Miscellaneous

Return every nth element in an array

Return every nth element in an array

Use Array.prototype.filter() to create a new array that contains every nth element of a given array. Source https://www.30secondsofcode.org/js/s/every-nth

Miscellaneous

  • « Go to Previous Page
  • Go to page 1
  • Interim pages omitted …
  • Go to page 6
  • Go to page 7
  • Go to page 8
  • Go to page 9
  • Go to page 10
  • Interim pages omitted …
  • Go to page 34
  • Go to Next Page »

Primary Sidebar

FREE UPDATES!

Get the latest updates in your inbox for FREE!

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2023 JavaScriptSource.com

  • About
  • Privacy Policy
  • Submit
  • FAQ
  • Jobs For Developers
  • Contact Us