このオブジェクトの配列をisActive値「True」で並べ替えるにはどうすればよいですか?
[{src: "SafeUrlImpl", id: "10047", filename: "Verify Event screenshot .jpg", fileType: "1", isActive: false},
{src: "SafeUrlImpl", id: "1006", filename: "Verify Event screenshot .jpg", fileType: "1", isActive: true},
{src: "SafeUrlImpl", id: "10045", filename: "Verify Event screenshot .jpg", fileType: "1", isActive: false},
{src: "SafeUrlImpl", id: "10045", filename: "Verify Event screenshot .jpg", fileType: "1", isActive: false}]
以下のようにisActive値Trueに基づく出力が必要です
[{src: "SafeUrlImpl", id: "1006", filename: "Verify Event screenshot .jpg", fileType: "1", isActive: true},
{src: "SafeUrlImpl", id: "10047", filename: "Verify Event screenshot .jpg", fileType: "1", isActive: false},
{src: "SafeUrlImpl", id: "10045", filename: "Verify Event screenshot .jpg", fileType: "1", isActive: false},
{src: "SafeUrlImpl", id: "10045", filename: "Verify Event screenshot .jpg", fileType: "1", isActive: false}]
この.sort()
方法を使用できます。
const result = data.sort((a,b) => +b.isActive - +a.isActive);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加