Skip to content

Instantly share code, notes, and snippets.

@vwedesam
Last active July 4, 2023 10:57
Show Gist options
  • Save vwedesam/c899de8315b945511917ef45e58d80b8 to your computer and use it in GitHub Desktop.
Save vwedesam/c899de8315b945511917ef45e58d80b8 to your computer and use it in GitHub Desktop.
remove duplicates in an array(JS)

remove duplicate in an array, string, object, number

works for string, object, number and all data type supported in Javascript

function removeDuplicates(arr) {
    let _arr = []
    return arr.filter((item, index) => {
        _arr.push(JSON.stringify(item))
        return _arr.indexOf(JSON.stringify(item)) == index
    });
}

Examples

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment