Finding the index position of a 2-dimensional array

I can show what I have tried still trying …

let res = "";

const data = [];
console.log(res);
res.split(']').forEach((el) => {
        if (!el) return;

    const [mac, ttl, time] = el.split(',');
    const obj = data.find(o => o.mac === mac);

    if (obj) {
        obj.ttl = ttl;
        obj.time = time;
    } else {
        data.push({ mac, ttl, time });
    }
});


for (var i = 0; i < data.length; i++) {
    let row = myTable.insertRow();
    let cell0 = row.insertCell(0);
    let cell1 = row.insertCell(1);
    let cell2 = row.insertCell(2);
    let cell3 = row.insertCell(3);
    cell0.innerHTML = i;
    cell1.innerHTML = data[i].mac;
    cell2.innerHTML = data[i].ttl;
    cell3.innerHTML = data[i].time;
    

}


setInterval(function() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
    
        if (this.readyState == 4 && this.status == 200) {
            res += this.responseText;
        };
    
};

xhr.open("GET", "http://192.168.43.154/wifimac", true);
xhr.send();

}, 5);

Here is an approach but I have not included splitting the string received from an XMLHttpRequest. Enter values for mac, ttl and time as if from an XMLHttpRequest and click ‘Update’.

Hi @rameshramboo59,

Did Archibald’s solution help you out, or are you still having trouble implementing this?

@rameshramboo59 There is a pretty decent article here, that might be worth a read :slight_smile:

Also at the end the article are two links, one on Javascript promises and one on async/await. It might give you some ideas.

1 Like