Answers for "find duplicate by one properties of object"

1

find duplicate values in array object javascript

function getUnique(arr, comp) {

                    // store the comparison  values in array
   const unique =  arr.map(e => e[comp])

                  // store the indexes of the unique objects
                  .map((e, i, final) => final.indexOf(e) === i && i)

                  // eliminate the false indexes & return unique objects
                 .filter((e) => arr[e]).map(e => arr[e]);

   return unique;
}

console.log(getUnique(arr,'id'));
Posted by: Guest on November-09-2020
0

find only duplicate data javascript object

export const findDuplicate = (data: Record<string, any>[]): number[] => {
	const duplicates: number[] = data
		.filter((item: Record<string, any>, index: number) => index !== data.findIndex((v: Record<string, any>) => v.order_id === item.order_id))
		.map((val: Record<string, any>) => val.id)

	return duplicates
}
Posted by: Guest on February-19-2022

Code answers related to "find duplicate by one properties of object"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language