lundi 30 novembre 2015

Jquery, check if multilevel array already has this in it or not

I am trying to push "arrayOne" into a multilevel array(arrayTwo). First I want to make sure it doesn't exist already so there is no duplicates. here is my code:

var arrayOne = ["3", "total_2"];
var arrayTwo = [["1", "total_2"], ["2", "total_4"], ["2", "total_6"], ["2", "total_11"]];

if (arrayTwo has arrayOne) {
    //do nothing
} else {
    arrayTwo.push(arrayOne);   
}

Im thinking im just confused on the syntax of this part:

if (arrayTwo has arrayOne) {

fiddle : http://ift.tt/1l3xrkt

Aucun commentaire:

Enregistrer un commentaire