Array not indexed at zero?

MatthewKMatthewK IL, USACommunity Member Qubie ✭

Array not indexed at zero?

Hello all,

I'm new to javascript and have been adapting Kurt Munz's method of carrying forward rank order questions:

It actually works fine. The rank order in question 1 is the item order in the constant sum question 2. The problem is that I then want to feed the constant sum data into a new array, sort the array based on the item descriptor, and then save those values as embedded variables. It is my way of putting the variables back into some kind of order for later data analysis. Otherwise the constant sum data is organized by the order the subject ranked things, rather than some constant order I can feed into a stat program.

Two things aren't working:

1.) it isn't sorting based on the descriptor.

2.) For some reason the new array indexes at [4] rather than [0]. So '${q://QID5/ChoiceNumericEntryValue/1}' is recorded in choice[4][0] rather than choice [0][0] (and so on through the list). Any thoughts on this? The former issue I can probably figure out by googling more on javascript. But I'm deeply confused on the latter. All embedded variables are declared in the survey flow.


{ // hide next button

$('NextButton') && $('NextButton').hide();

// store score in first column, description in second column of array "choice"

var choice = [ 




 ['${q://QID5/ChoiceNumericEntryValue/4}','${q://QID5/ChoiceDescription/4}'],    ['${q://QID5/ChoiceNumericEntryValue/5}','${q://QID5/ChoiceDescription/5}'],









// sort choice BY DESCRIPTION


function sortFunction(a, b) {

  if (a[1] === b[1]) {

    return 0;


  else {

    return (a[1] < b[1]) ? -1 : 1;















// advance to next screen




  • MatthewKMatthewK IL, USACommunity Member Qubie ✭
    edited October 24

    Problem solved(ish)!

    So, you know how Qualtrics tracks when you delete response options? My survey had "default" recoded values of 4-15 on the critical question. Manually setting the recodes to 1-12 or clearing recodes did not fix the problem, even with all test responses deleted. When Qualtrics support COPIED the survey the problem was fixed. Apparently a copy of a survey does not carry over the "history" of deleted response options. Oddly, this only appears to be true if the survey is copied by Qualtrics support. I tried it myself and it failed.

    The apparent failure of the search function was due to a combination of the other problem and the search function putting capitalized terms first.

Sign In to Comment