jsオブジェクトのソートに関連する他の多くの質問がありました。そのほとんどは、.mapメソッドを使用してオブジェクトまたはオブジェクトの配列を値に基づいてソートすることを推奨しがちですプロパティが、私は少し異なるものを達成しようとしています。オブジェクトプロパティの値に基づくJSオブジェクトの変換
私は、このオブジェクトのフォーマットターンしようとしています:
{
"example-repo-1": [
{
"repository": "example-repo-1",
"commit_hash": "example-hash-1"
},
{
"repository": "example-repo-1",
"commit_hash": "example-hash-1.2"
}
],
"example-repo-2": [
{
"repository": "example-repo-2",
"commit_hash": "example-hash-2"
}
]
}
は、だから私は私の元のオブジェクトを取得する必要があります。このような「リポジトリ」の値を使用してフォーマットされたオブジェクトに
{
"commits": [
{
"repository": "example-repo-1",
"commit_hash": "example-hash-1"
},
{
"repository": "example-repo-1",
"commit_hash": "example-hash-1.2"
},
{
"repository": "example-repo-2",
"commit_hash": "example-hash-2"
}
]
}
をこれは、リポジトリプロパティの値の後に名前が付けられ、そのプロパティ値に一致する各オブジェクトを含む多数の配列を含むオブジェクトを返すために、他のオブジェクトの配列を持つオブジェクトです。