Extracting uniqueValues into an array

312
1
Jump to solution
01-30-2023 08:43 AM
TheGamer
Occasional Contributor
let layer = new FeatureLayer({
  portalItem: { id: "5ce5374a461e45bab714b43ffedf151d" }
});

uniqueValues({
  layer: layer,
  field: "Candidate"
}).then(function(response){
  // prints each unique value and the count of features containing that value
  let infos = response.uniqueValueInfos;
  infos.forEach(function(info){
    console.log(info.value);
  });
});

 

I'm struggling on how to store the info.value into a new Array

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
KristianEkenes
Esri Regular Contributor
let layer = new FeatureLayer({
  portalItem: { id: "5ce5374a461e45bab714b43ffedf151d" }
});

uniqueValues({
  layer: layer,
  field: "Candidate"
}).then(function(response){
  
  let infos = response.uniqueValueInfos;
  const values = infos.map((info) => info.value);
});

 

Just call Array.map() and return the value in the callback. That will create a new array with only the values.

View solution in original post

0 Kudos
1 Reply
KristianEkenes
Esri Regular Contributor
let layer = new FeatureLayer({
  portalItem: { id: "5ce5374a461e45bab714b43ffedf151d" }
});

uniqueValues({
  layer: layer,
  field: "Candidate"
}).then(function(response){
  
  let infos = response.uniqueValueInfos;
  const values = infos.map((info) => info.value);
});

 

Just call Array.map() and return the value in the callback. That will create a new array with only the values.

0 Kudos