1loc – Single Line JavaScript Snippets

1loc is a site packed with small JavaScript snippets that take up 1 line of code.

For example:

  • Compare Two Dates

    const compare = (a, b) => a.getTime() > b.getTime();
  • Generate Number in Range

    const random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
  • Get all siblings of an element

    const siblings = ele => [].slice.call(ele.parentNode.children).filter((child) => (child !== ele));

1loc | Favorite JavaScript single line of code →

Published by Bramus!

Bramus is a Freelance Web Developer from Belgium. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.