JSFiddle - React, Tailwind, and code Playground

HTML

<ul class="list">
    <li data-id="l1">list 1</li>
    <li data-id="l2">list 2</li>
    <li data-id="l3">list 3</li>
    <li data-id="l4">list 4</li>
</ul>
<p></p>

JavaScript

var arr = new Array();
var counter = 0;
    
    $('.list li').each(function(){
        var lid = $(this).attr('data-id');
        var lval = $(this).html();
        arr[lid] = lval;
        counter++;
    });
    
    $('p').html('array length = ' + counter + ' & index of list 1 is l1');