1

Take look at:

https://jsfiddle.net/3fmp43db/

data = [{
  city: 'Mushroom Kingdom',
}, {
  city: 'Mushroom Kingdom',
}, {
  city: 'Mushroom Kingdom',
}, {
  city: 'Mushroom Kingdom',
}, {
  city: 'Mushroom Kingdom',
}, {
  city: 'Mushroom Kingdom',
}, {
  city: 'Planet Zebes',
}, {
  city: 'Planet Zebes',
}, {
  city: 'Planet Zebes',
}];


for(var i = 0; i < data.length; i++) {
    var obj = data[i];

   $(".test").append(obj.city + "<br>")
}   

It's simple problem, I couldn't figure out how to remove duplicated values before to render this list.

1 Answer 1

2

change last for loop from

for(var i = 0; i < data.length; i++) {
    var obj = data[i];

   $(".test").append(obj.city + "<br>")
}

to

var allCities = {};
for(var i = 0; i < data.length; i++) {
    allCities[ data[i].city ] = "";
}
$(".test").append(Object.keys( allCities ).join("<br>"));

check this updated fiddle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.