How to loop with jquery without duplicates

0

I wanted to know if you can loop inside the other using the each function without duplicating the values

Example

var cor = ["branco", "preto"];
var exa = ["#FFF" ,"#000"];


$.each(cor, function(index, values){
    $.each(exa, function(index1, values1){
        console.log(values + values1);
    }); 
});

Every time I run this example the result goes like this:

branco#FFF
branco#000 
preto#FFF 
preto#000
    
asked by anonymous 25.02.2017 / 22:17

1 answer

0

Then, you only have to do it once, and get the index to bring the dice to second.

Example:

var cor = ["branco", "preto"];
var exa = ["#FFF" ,"#000"];


$.each(cor, function(index, value){
    console.log(value + " " + exa[index]);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
25.02.2017 / 22:35