Javascript Make Sure Inputs all Have Unique Values

Ok, I know I'm overthinking this, because it just isn't coming to me at all. I have a group of inputs. How would I go about checking to make sure that their values are all unique? Thanks!


var inputs=[], flag=false;
    if ($.inArray(this.value, inputs) != -1) flag=true ;

if (flag==true) {
   //duplicates exists

It seems to be a validation issue. You can do in the odd way (with a heavy bunch of if clauses, which I guess is not desired), trying to add all those inputs in an array and check them inside a while loop. Or perhaps, if those inputs are strings, you can concat them and try something with regexps.

There should be more answers for this, and sure better that the one summoned here.

Use this pseudo-set implementation and check that each entry isn't already repeated That is, iterate and check, if x in set return false

function uniqueValues(elements) {

    var values = {},
        len = elements.length,
        i = 0;

    for (; i < len; i++) {
        if (!values[elements[i].value]) values[elements[i].value] = true;
        else return false;
    return true;

use this

var areUnique = true;
var val = $(this).val();
   if(val == $(this).val()){areUnique = false;}
//check the value of areUnique here

Need Your Help

"scanf with printf" vs "fgets with printf"

c printf scanf fgets

I know about the difference and the advantage/disatvantage of using scanf and fgets.

mongoose difference of findOneAndUpdate and update

mongodb mongoose

What is difference of findOneAndUpdate and update?