There's multiple issues:
somethingIsTrue ? doSomething();
is not valid in JavaScript. See MDN on ternary operator- Frankly, I don't think
Array.prototype.reduce
is the right choice. Reduce creates something from all array members. I mean you could use it for this, but the code would be unnecesarily obscure. For generic looping, use eithermap
(1:1 conversion of array elements) orforEach
I'd use forEach
, or just classic for
:
var d_loc = [{'Common Name': "Foo"}, {'Common Name':"Bar"}, {'Common Name': "Foo"}];
const accounts = [];
const result = d_loc.forEach( (userInfo) => {
const name = userInfo['Common Name'];
if(accounts.indexOf(name)<0)
accounts.push(name)
} ,
[] )
console.log(accounts);