Skip to content

Instantly share code, notes, and snippets.

@andrewmmc
Last active January 16, 2018 04:49
Show Gist options
  • Save andrewmmc/9851d874fc5a359cbc248a9029c80646 to your computer and use it in GitHub Desktop.
Save andrewmmc/9851d874fc5a359cbc248a9029c80646 to your computer and use it in GitHub Desktop.
[JavaScript] Flatten object

JavaScript - Flatten object

  let dateTimeList = [
        {
            "timestamps": {
                "driverRouteTime": "2018-01-12T07:33:21.791Z"
            }
        },
        {
            "timestamps": {
                "driverRouteTime": "2018-01-12T07:11:20.260Z"
            }
        },
        {
            "timestamps": {
                "driverRouteTime": "2018-01-12T06:32:30.278Z"
            }
        }
    ];
  
  dateTimeList = dateTimeList.map(function(elem) {
    return elem.timestamps.driverRouteTime
  });
  
  console.log(dateTimeList);

In ES6 way,

dateTimeList = dateTimeList.map(elem => elem.timestamps.driverRouteTime)

Expected output:

["2018-01-12T07:33:21.791Z", "2018-01-12T07:11:20.260Z", "2018-01-12T06:32:30.278Z"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment