Q:

$.inArray not working

i am having a problem regarding storing objects into array.  But when i try to check the existence of object using $.inArray, it always returns -1.  i am using angularjs. 
<input name="{{question.number}}"
            ng-click="radioSelected(question.choiceOneWeight, question.number,question.tmiGroup)"
            type="radio" value="{{question.choiceOneWeight}}" />

$scope.radioSelected = function(choice, question, tmiGroup) {
        var answer = {};
        answer.questionNumber = question;
        answer.answerWeight = choice;
        answer.tmiGroup = tmiGroup;

        if($.inArray(answer,userAnswers) < 0){
            userAnswers.push(answer);
        }
    };

my generated answer object is 
{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"}

if i click on radio button multiple times, 
userAnswers array looks like :
[{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},
{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},

{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},

{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},

{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},

{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},

{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},

{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},

{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},

{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},

{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},

{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},

{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},

{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},

{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},

{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},

{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"}]

A:

You cannot use inArray() for comparing anything that is not comparable using a simple ===
For example:
var a = [{x: 1}];
$.inArray({x: 1}, a); // => -1

In your case, you can store a JSON stringified version of each question in the array and then use .inArray() on that. 
i.e.
var answer = JSON.stringify({
    questionNumber: question,
    answerWeight: choice,
    tmiGroup: tmiGroup
});

// now you can use inArray as 'answer' is nothing but a string (JSON)
if($.inArray(answer, userAnswers) < 0){
    userAnswers.push(answer);
}

Remember to do JSON.parse() when retrieving the questions back from userAnswers

