我想對從我的API返回的多維數組進行排序,以允許用戶根據節拍選擇一個範圍。按範圍對JavaScript中的多維關聯數組排序
說實話我真的堅持我的api返回。
var myObj = [{
title: 'title one',
beats: 1
}, {
title: 'title two',
beats: 2
}, {
title: 'title three',
beats: 3
}, {
title: 'title four',
beats: 4
}, {
title: 'title five',
beats: 5
}, {
title: 'title six',
beats: 6
}, {
title: 'title seven',
beats: 7
}, {
title: 'title eight',
beats: 8
}, {
title: 'title nine',
beats: 9
}, {
title: 'title ten',
beats: 10
}];
現在我試圖讓用戶選擇基於節拍的範圍。
所以,如果他們選擇1-4會返回。
var myObj = [{
title: 'title one',
beats: 1
}, {
title: 'title two',
beats: 2
}, {
title: 'title three',
beats: 3
}];
和8-10將返回等等...
var myObj = [{
title: 'title eight',
beats: 8
}, {
title: 'title nine',
beats: 9
}, {
title: 'title ten',
beats: 10
}];
我會用什麼功能來做到這一點希望得到任何幫助?
您的myObj不是一個數組,它是一個包含數字的對象作爲屬性。是否有可能讓myObj成爲真正的數組? – 2014-09-22 16:49:15
嗨馬丁我更新了問題 – user1503606 2014-09-22 17:07:46
嗨user1503606。 **保羅**的回答非常好。爲了完成任務,我發佈了一個數組用法的答案。 – 2014-09-22 19:00:39