Alan Fitch
09/15/2021, 12:27 PMericbirdsall
09/15/2021, 12:58 PMAlan Fitch
09/15/2021, 12:59 PMericbirdsall
09/15/2021, 1:06 PMconst selectOptions = [{
text: "Select B",
value: "select_b"
}, {
text: "Select C",
value: "select_c"
}, {
text: "Select A",
value: "select_A"
}];
// From: <https://stackoverflow.com/questions/21131224/sorting-json-object-based-on-attribute>
function sortByKey(array, key) {
return array.sort(function (a, b) {
var x = a[key];
var y = b[key];
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
});
}
const sortedOptions = sortByKey(selectOptions, 'text');
sortedOptions.forEach(option => {
yourSelectField.addSelectOption({
value: option.value,
text: option.text,
})
});
ericbirdsall
09/15/2021, 1:10 PMAlan Fitch
09/15/2021, 1:20 PM