You can assemble an array with the value of how many elements each li
has. It would look something like this:
var contador = $('ul li').get().reduce(function(obj, li) {
obj[li.id] = li.children.length;
return obj;
}, {});
console.log(contador);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><ul><liid='li1'><a>elemento1</a><a>elemento2</a><a>elemento3</a></li><liid='li2'><a>elemento1</a><a>elemento2</a><a>elemento3</a></li></ul>
WithmodernjavascriptitwasnotnecessarytojQueryandwouldlooklikethis:
var contador = [...document.querySelectorAll('ul li')].reduce(
(obj, li) => (obj[li.id] = li.children.length, obj), {}
);
console.log(contador);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li id='li1'>
<a>elemento 1</a>
<a>elemento 2</a>
<a>elemento 3</a>
</li>
<li id='li2'>
<a>elemento 1</a>
<a>elemento 2</a>
<a>elemento 3</a>
</li>
</ul>