I have an array as below
var abc = [11,2,11,3,11,4,9,5]
I am actually appending the data into datatables, and it would be like this as of now
11|2
11|3
11|4
9 |5
So my question is, i want it to check if there is a duplicate/same value in index 0, and add everything in index 1, example as below
11|9
9 |5
Is is possible for me to do that? I have tried the below but still not working
for (var a = 0; a < x.length; a++) {
if (x[0] !== -1){
alert(x[0]);
} else {
console.log("no same value found");
}
}
But still no luck making it to work. Appreciate any help that i can get.
Thanks
if (x[0] !== -1){does not seem anything like trying to see if a value is unique. The syntax of your input is not valid eitherabcarray actually contains? Try the following in the JavaScript console and look at what it displays. Is it what you expect?console.log([11,2|11,3|11,4|9,5])