0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

JavaScript 日付ありオブジェクトの配列をソートする

Posted at

##概要
DynamoDB で日付を含むデータを取得し、新しい順で並び変えたときの備忘録です。

##ソースコード

var Items = [
    {
        userId: "0001",
        createdAt: "2021-06-03T06:10:18.782Z"
    },
    {
        userId: "0002",
        createdAt: "2021-06-03T07:06:47.336Z"
    }
];

Items.sort((a,b) => new Date(b.createdAt) - new Date(a.createdAt));

console.log(Items);

##結果

[ { userId: '0002', createdAt: '2021-06-03T07:06:47.336Z' },
  { userId: '0001', createdAt: '2021-06-03T06:10:18.782Z' } ]
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?