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


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

};"GET", "http://i have hide this /wifimac", true);

}, 1000);

let array = [];
function snifferOnServer(x) 

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

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


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


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

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 as you can see in image i have consoled a output of macIdData . So This value is getting stored in an array .

this data contains mac|ttl(time to leave) | status/time

So I need to create logic. If I check if Mac exists on that array, if yes, I only need to update the other value, for example.

//mac ,ttl,status

If above mac already exists on the array, I will just overwrite the other two columns with a new value which is ttl status

Thank You

Use an object.

data = {}

//new data in;
data[newdata[0]] = [newdata[1],newdata[2]]


(heck if you wanna be fancy, make the two item array another object)
data[newdata[0]] = {"ttl":newdata[1], "status":newdata[2]}

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