7
I’m making a custom search filter where the user can select the brand and product features and I return their id.
But I wanted to return only the last record of mine arrays where they contain all the information I need.
I just need to return the last record presented in the console as in the image below. Ex: mark=25,30,53 and feature:10:35:4
Follows the code:
<a href="#" class="filter-link">
<div class="label_check">
<input type="checkbox" id="marca-4" class="filter-check" data-tipo="marca?4" value="4">
<div class="filter-pretty-check"></div>
<span class="filter-desc">Nokia</span>
</div>
</a>
$('#filtrar-opcoes').on('click',function(){
var tipos = [];
var caracteristicas = [];
$.each(($("input[type=checkbox]:checked")),function(index, obj){
var $tipo = $(obj).attr('data-tipo');
if($tipo.split('?')[0] == 'marca'){
tipos.push($tipo.split('?')[1]);
var firstPartUrl = $tipo.split('?')[0] + '=' + tipos.join();
console.log(firstPartUrl);
}
if($tipo.split('?')[0] == 'caracteristica'){
caracteristicas.push($tipo.split('?')[1]);
var lastPartUrl = $tipo.split('?')[0] + '=' + caracteristicas.join(':');
console.log(lastPartUrl);
}
});
});
Very confusing your code. Could you post the html structure ? Mainly with the attributes
data-tipo
?– DontVoteMeDown
@Dontvotemedown already added a piece of the html structure
– Gabriel Schmidt Cordeiro
@Gabrielschmidtcordeiro the two answers below don’t work for you?
– Jéf Bueno
@Jéfersonbueno no cara. I just need to return the last record presented on the console as in the image above. Ex: brand=25,30,53 and feature:10:35:4
– Gabriel Schmidt Cordeiro
Then edit your question and explain what your problem is and what you’re trying to do. If you read the title of your question you will see that the two answers do exactly what is said there.
– Jéf Bueno