Skip to content

Instantly share code, notes, and snippets.

@EminenceHC
Last active October 1, 2015 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EminenceHC/e85538de1f02923c1968 to your computer and use it in GitHub Desktop.
Save EminenceHC/e85538de1f02923c1968 to your computer and use it in GitHub Desktop.
select options from array
// I am using ajax to get an array of values which I want to turn into select options.
// When I log my array to console this is what I get:
Array[2], each item in the array looks like this:
Array[2]
0: "Abstain from substance abuse and participate in a recovery-based program."
1: 1
1: Array[2]
0: "Engage in healthy, safe alternative activities to substance abuse that do not cause cognitive, behavioral, or emotional changes."
1: 5
// Stringified the above array looks like this:
[["Abstain from substance abuse and participate in a recovery-based program.",1],["Accept the powerlessness and unmanageability over mood-altering substances and participate in a recovery-based program.",2],["Engage in healthy, safe alternative activities to substance abuse that do not cause cognitive, behavioral, or emotional changes.",5]]
// I am trying to figure out how I can take that array parse each item into an option, the last number in the array should be the actual option's value, and the text should be the label.
// I want to then be able to take that and update a select field like:
$('.my-select-field').empty().append(array-from-above);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment