Answers for "js array find count dublicate"

1

get duplicate values from array javascript

// This code was pasted by ProgrammerRimon, 2022-02-18
// Find dublicates numbers from array;

const a = [1,1,1,3,3,4,5,5,6,7,8,8,8,8,8,9,2];

function findDublicatesNumbersFromArray(a) {
    var d = [];
    for (let i = 0; i < a.length; i++) {
        var ct = a[i];
        var cmt = 0;
        for(var x = 0; x<a.length;++x) {
            if(ct === a[x]) {
                cmt++
                if(cmt > 1) {
                    d.push(a[i])
                }
            }
        }
    }
    return d.filter((i, ix)=> d.indexOf(i) === ix);
}

console.log(findDublicatesNumbersFromArray(a))
Posted by: Guest on February-18-2022
1

javascript create array with repeated values

Array(5).fill(2)
//=> [2, 2, 2, 2, 2]
Posted by: Guest on February-17-2021
1

how to get duplicate values from array in javascript

const names = ['Mike', 'Matt', 'Nancy', 'Adam', 'Jenny', 'Nancy', 'Carl']

const count = names =>
  names.reduce((a, b) => ({ ...a,
    [b]: (a[b] || 0) + 1
  }), {}) // don't forget to initialize the accumulator

const duplicates = dict =>
  Object.keys(dict).filter((a) => dict[a] > 1)

console.log(count(names)) // { Mike: 1, Matt: 1, Nancy: 2, Adam: 1, Jenny: 1, Carl: 1 }
console.log(duplicates(count(names))) // [ 'Nancy' ]
Posted by: Guest on June-19-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language