DeveloperBreeze

Calculating the Average of an Array in JavaScript

const numbers = [10, 15, 20, 25, 30];
const average = numbers.reduce((acc, curr) => acc + curr, 0) / numbers.length;
console.log('Average of Array Elements:', average);

Continue Reading

Discover more amazing content handpicked just for you

Cheatsheet
javascript

JavaScript Utility Libraries Cheatsheet

Date-fns is a modern JavaScript date utility library that provides over 200 functions for manipulating dates without modifying native JavaScript objects.

<table>
  <tr>
    <th>Function</th>


 <th>Description</th>
    <th>Example</th>
  </tr>
  <tr>
    <td><code>format(date, formatString)
    Formats the date according to the provided format string.
    format(new Date(), 'MMMM do, yyyy') => 'September 20th, 2024'
  
  
    addDays(date, amount)
    Returns a new date with the specified number of days added.
    addDays(new Date(), 10) => Date object 10 days in the future
  
  
    differenceInDays(dateLeft, dateRight)
    Returns the number of days between two dates.
    differenceInDays(new Date('2024-09-20'), new Date('2024-09-10')) => 10
  
  
    isBefore(date, dateToCompare)
    Checks if the first date is before the second one.
    isBefore(new Date('2024-09-10'), new Date('2024-09-20')) => true
  
  
    parse(dateString, formatString, referenceDate)
    Parses a date string according to the provided format string.
    parse('20th September 2024', 'do MMMM yyyy', new Date()) => Date object for 20th September 2024
  

Aug 21, 2024
Read More
Code
javascript

JavaScript Sum of Array Elements

No preview available for this content.

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!