So I've been trying to find a solution to remove unique elements from an object array and keep the duplicates but almost all the questions are on how to remove duplicates.
The array looks like this:
[{"No":"123","Product":"Name X","Color":"blue"},
{"No":"123","Product":"Name X","Color":"green"},
{"No":"456","Product":"Name X2","Color":"red"},
{"No":"456","Product":"Name X2","Color":"blue"},
{"No":"789","Product":"Name X3","Color":"yellow"}]
I need to check No
if it's unique and remove it if it is. The array would look like this afterwards:
[{"No":"123","Product":"Name X","Color":"blue"},
{"No":"123","Product":"Name X","Color":"green"},
{"No":"456","Product":"Name X2","Color":"red"},
{"No":"456","Product":"Name X2","Color":"blue"}]
I tried doing get only the duplicates in the first place (MySQL), but all the solutions involved using GROUP BY
and HAVING
which did return only the duplicate rows but did also combine them.