getAnswersCodes()
The getAnswersCodes() function (client-side and server-side) retrieves the codes associated with the selected answers for a question. The code corresponds to the value in the Code field on the answer record.
Syntax
Use this syntax for the getAnswersCodes() function:
getAnswersCodes('QUESTION_CODE');
Return Value
The getAnswersCodes() function returns an array of strings with the answer codes. The codes are returned in the order in which users selected the answers.
[
'string1',
'string2',
'string3',
// ...
]
Parameters
The question code is required.
The getAnswersCodes() function accepts the question code as a string parameter. You can find it in the Code field on the question record.
Examples
The following examples show how to use the getAnswersCodes() function.
Retrieving the Selected Answer Codes for a Question
This example retrieves the selected answer codes for the "Select color" question, which has the code COLOR.
const answersCodes = getAnswersCodes('COLOR');
console.log(answersCodes);
Suppose the question the following answers:
-
Blue (code BLUE)
-
Beige (code BEIGE)
-
Gray (code GRAY)
-
Yellow (code YELLOW)
If a user selects "Yellow", "Beige", and "Gray", the function returns the following array:
[
"YELLOW",
"BEIGE",
"GRAY"
]