I'm doing a custom search filter where the user can select the brand and the characteristics of the product and I return the id of them.
But I wanted to return only the last record of my arrays where they contain all the information I need.
I need only return the last record displayed in the console as in the image below. Ex: mark = 25,30,53 and feature: 10: 35: 4
Follow 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);
}
});
});