How to loop with jquery without duplicates

Asked

Viewed 366 times

0

I wanted to know if you can make a loop inside the other using the function each 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 comes out like this:

branco#FFF
branco#000 
preto#FFF 
preto#000

1 answer

0


So you only need to do it once, and take the dice 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>

  • 1

    Thanks, it worked perfectly!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.