0

How do I remove all values that are duplicated? So only nondublicated values are left.

const sample = [["08:00",true,],["09:00",true,],["09:00",false,], ["10:00",true,]]

const newArray = [["08:00", true,], ["10:00",true,]]
Jonas Bro
  • 63
  • 9
  • Please add the code you've attempted to your question as a [mcve]. – Andy May 19 '22 at 10:14
  • 1
    Does this answer your question? [JS: remove duplicate values in array, including the original](https://stackoverflow.com/questions/40715503/js-remove-duplicate-values-in-array-including-the-original) – axtcknj May 19 '22 at 10:17

2 Answers2

3

Try this :

const sample = [["08:00",true,],["09:00",true,],["09:00",false,], ["10:00",true,]];

const flatArr = sample.flat();

const res = sample.filter((arr, index) => flatArr.indexOf(arr[0]) === flatArr.lastIndexOf(arr[0]));

console.log(res);
Debug Diva
  • 26,058
  • 13
  • 70
  • 123
0

Try this:

const sample = [
    ["08:00",true,],
    ["09:00",true,],
    ["09:00",false,],
    ["10:00",true,]
    ];
const newArray = [
    ["08:00", true,], 
    ["10:00", true,]
    ];
    
function checkDuplicate (array) {
    let output = [];
    array.forEach(function(item) {
        if(!JSON.stringify(output).includes(JSON.stringify(item))){
            output.push(item);
        }
    });
    return output;
}
console.log(checkDuplicate([...sample,...newArray]));
Nikhil
  • 81
  • 7