Storing an array value into an array value with no repeat value

Hello,

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

	}
};
xhr.open("GET", "http://i have hide this /wifimac", true);
xhr.send();

}, 1000);



let array = [];
function snifferOnServer(x) 
{

    let obj = x.split(']');
    //console.log(obj);
    for (let i = 0; i < obj.length; i++) {
        mac = obj[i];
        macIdData = mac.split(",");
        console.log(macIdData);

        array = [...array, [macIdData]];
    }
    


}

So in the program, I am getting a string of values from a server, and it looks like this:

403D,55,59]42348,55,58]4C85,56,58]

So I have used the split function to separate every set of data.

As you can see, myObj is constantly receiving data, which I need to store in an array so that I can display it on an HTML page later. So after I again split and target ", " now data look like this

Capture

And then I started storing values in array = [...array, [macIdData]];

But the problem is that macIdData contains a repeated value, which I don’t want to store in that array. so basically data consist of

403D,55,59
//mac,ttl,onlinetime

So I need to check if Mac is already presented, and if it is, I need to overwrite it at the same position with the updated ttl and status.I tried a lot But I am not able to do it if someone has any solution for this thank you so much

hey , i recomend that you take a look at the ( set object ) in JS , i found it quite helpeful and fast in situations like this .

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.