Skip to main content
added 60 characters in body
Source Link
Vincent Chua
  • 1k
  • 6
  • 21
  • 41

I have an array and I would like to create another new array and the values are extracted from the HTML itself, then I would like to compare both the values and output the match value.

My existing array to compare:

var designersArrSelected = ["Von Blan","Foo Can","Diane con Fursternberg","BCBG MAX Azria"]; 

My HTML

<ul id="seasonsDropDown"> <li data-season="FALL 2013 HAUTE COUTURE">FALL 2013 HAUTE COUTURE <ul class="designers"> <li data-designer="Alexander Wang">Alexander Wang</li> <li data-designer="BCBG MAX Azria">BCBG MAX Azria</li> <li data-designer="Diane con Fursternberg">Diane con Fursternberg</li> <li data-designer="Diane Von De">Diane Von De</li> </ul> </li> </ul> 

To grab the all designer's names from the HTML I've used:

var designersArrAll = []; var i = 0; $(".designers>li").each(function(){ designersArrAll[i++] = $(this).attr("data-designer"); }); 

Base on my example the outcome should select "Diane con Fursternberg" and "BCBG MAX Azria since there are two matches, but how should I compare both the arrays for the same values?

Here is the pen: http://codepen.io/vincentccw/pen/eDrox

I have an array and I would like to create another new array and the values are extracted from the HTML itself, then I would like to compare both the values and output the match value.

My existing array to compare:

var designersArrSelected = ["Von Blan","Foo Can","Diane con Fursternberg","BCBG MAX Azria"]; 

My HTML

<ul id="seasonsDropDown"> <li data-season="FALL 2013 HAUTE COUTURE">FALL 2013 HAUTE COUTURE <ul class="designers"> <li data-designer="Alexander Wang">Alexander Wang</li> <li data-designer="BCBG MAX Azria">BCBG MAX Azria</li> <li data-designer="Diane con Fursternberg">Diane con Fursternberg</li> <li data-designer="Diane Von De">Diane Von De</li> </ul> </li> </ul> 

To grab the all designer's names from the HTML I've used:

var designersArrAll = []; var i = 0; $(".designers>li").each(function(){ designersArrAll[i++] = $(this).attr("data-designer"); }); 

Base on my example the outcome should select "Diane con Fursternberg" and "BCBG MAX Azria since there are two matches, but how should I compare both the arrays for the same values?

I have an array and I would like to create another new array and the values are extracted from the HTML itself, then I would like to compare both the values and output the match value.

My existing array to compare:

var designersArrSelected = ["Von Blan","Foo Can","Diane con Fursternberg","BCBG MAX Azria"]; 

My HTML

<ul id="seasonsDropDown"> <li data-season="FALL 2013 HAUTE COUTURE">FALL 2013 HAUTE COUTURE <ul class="designers"> <li data-designer="Alexander Wang">Alexander Wang</li> <li data-designer="BCBG MAX Azria">BCBG MAX Azria</li> <li data-designer="Diane con Fursternberg">Diane con Fursternberg</li> <li data-designer="Diane Von De">Diane Von De</li> </ul> </li> </ul> 

To grab the all designer's names from the HTML I've used:

var designersArrAll = []; var i = 0; $(".designers>li").each(function(){ designersArrAll[i++] = $(this).attr("data-designer"); }); 

Base on my example the outcome should select "Diane con Fursternberg" and "BCBG MAX Azria since there are two matches, but how should I compare both the arrays for the same values?

Here is the pen: http://codepen.io/vincentccw/pen/eDrox

Source Link
Vincent Chua
  • 1k
  • 6
  • 21
  • 41

jQuery compare two arrays?

I have an array and I would like to create another new array and the values are extracted from the HTML itself, then I would like to compare both the values and output the match value.

My existing array to compare:

var designersArrSelected = ["Von Blan","Foo Can","Diane con Fursternberg","BCBG MAX Azria"]; 

My HTML

<ul id="seasonsDropDown"> <li data-season="FALL 2013 HAUTE COUTURE">FALL 2013 HAUTE COUTURE <ul class="designers"> <li data-designer="Alexander Wang">Alexander Wang</li> <li data-designer="BCBG MAX Azria">BCBG MAX Azria</li> <li data-designer="Diane con Fursternberg">Diane con Fursternberg</li> <li data-designer="Diane Von De">Diane Von De</li> </ul> </li> </ul> 

To grab the all designer's names from the HTML I've used:

var designersArrAll = []; var i = 0; $(".designers>li").each(function(){ designersArrAll[i++] = $(this).attr("data-designer"); }); 

Base on my example the outcome should select "Diane con Fursternberg" and "BCBG MAX Azria since there are two matches, but how should I compare both the arrays for the same values?