Skip to content

Sort array by date JavaScript | Example code

  • by

To sort an array by date first convert given strings into dates, and then subtract them to get a value that is either negative, positive, or zero.

  return new Date( - new Date(;

Sort array by date JavaScript

Simple example code parse strings to get Date objects, then sort by compare function.

<!DOCTYPE html>

    var a = [
      "name": "February",
      "date": "2018-02-04T17:00:00.000Z",
      "name": "March",
      "date": "2018-03-04T17:00:00.000Z",
      "name": "January",
      "date": "2018-01-17T17:00:00.000Z",

      return new Date( - new Date(




Sort array by date JavaScript

Using the arrow function way


Do comment if you have any doubts or suggestions on this JS array topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

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