javascript unique string array case insensitive but keep one case sensitive result
问题 What do I mean with this? First let's look at some code I wrote: let names = ['James', 'james', 'bob', 'JaMeS', 'Bob']; let uNames = {}; names.forEach(n => { let lower = n.toLowerCase(); if (!uNames[lower]) { uNames[lower] = n; } }); names = Object.values(uNames); console.log(names); // >>> (2) ["James", "bob"] The goal here is to unique the given array case insensitive but keep one of the original inputs. I was wondering if there is a more elegant/better performing solution to this problem