javascript - Array.filter first of value -


i have json array based on structure:

[     {property1: "bmw", property2: value, property3: value, property4: value},     {property1: "mercedes", property2: value, property3: value, property4: value},     {property1: "bmw", property2: value, property3: value, property4: value},     {property1: "nissan", property2: value, property3: value, property4: value} ] 

how can filter array find first time new value appears property1 , store in separate array?

i array like: ["bmw", "mercedes", "nissan"]

if want store unique values, should use javascript built in-object set()

the method .add(value) append value set if doesn't exist

let carnames = new set();  let cars= [      { property1: "bmw" },      { property1: "mercedes" },      { property1: "bmw" },      { property1: "nissan" }  ];    cars.foreach(car => carnames.add(car.property1));    console.log(carnames.size);  (let name of carnames) {     console.log(name);  }


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -