1

Why am I not able to map display names in an array/Object in the following code?

var data = [{
    "displayFieldName": "",
    "fieldAliases": {
      "OBJECTID": "OBJECTID"
    },
    "fields": [{
      "name": "OBJECTID",
      "type": "esriFieldTypeOID",
      "alias": "OBJECTID"
    }],
    "features": [{
        "attributes": {
          "OBJECTID": 649
        }
      },
      {
        "attributes": {
          "OBJECTID": 665
        }
      },
      {
        "attributes": {
          "OBJECTID": 762
        }
      }
    ]
  },
  {
    "displayFieldName": "",
    "fieldAliases": {
      "display": "display",
      "OBJECTID": "OBJECTID"
    },
    "geometryType": "esriGeometryPoint",
    "spatialReference": {
      "wkid": 4326,
      "latestWkid": 4326
    },
    "fields": [{
        "name": "display",
        "type": "esriFieldTypeString",
        "alias": "display",
        "length": 50
      },
      {
        "name": "OBJECTID",
        "type": "esriFieldTypeOID",
        "alias": "OBJECTID"
      }
    ],
    "features": [{
        "attributes": {
          "display": "Transformer",
          "OBJECTID": 1537
        },
        "geometry": {
          "x": -88.17602806699995,
          "y": 41.78431233100008
        }
      },
      {
        "attributes": {
          "display": "Transformer",
          "OBJECTID": 1591
        },
        "geometry": {
          "x": -88.17546081099994,
          "y": 41.783341919000065
        }
      }
    ]
  },
  {
    "displayFieldName": "",
    "fieldAliases": {
      "display": "display",
      "OBJECTID": "OBJECTID"
    },
    "geometryType": "esriGeometryPoint",
    "spatialReference": {
      "wkid": 4326,
      "latestWkid": 4326
    },
    "fields": [{
        "name": "display",
        "type": "esriFieldTypeString",
        "alias": "display",
        "length": 50
      },
      {
        "name": "OBJECTID",
        "type": "esriFieldTypeOID",
        "alias": "OBJECTID"
      }
    ],
    "features": [{
        "attributes": {
          "display": "Service Point",
          "OBJECTID": 13597
        },
        "geometry": {
          "x": -88.17599727899994,
          "y": 41.78465526100007
        }
      },
      {
        "attributes": {
          "display": "Service Point",
          "OBJECTID": 13598
        },
        "geometry": {
          "x": -88.17595382899998,
          "y": 41.78455803400004
        }
      },
      {
        "attributes": {
          "display": "Service Point",
          "OBJECTID": 13599
        },
        "geometry": {
          "x": -88.17582231499995,
          "y": 41.78435312600004
        }
      },
      {
        "attributes": {
          "display": "Service Point",
          "OBJECTID": 13600
        },
        "geometry": {
          "x": -88.17561004899994,
          "y": 41.784005335000074
        }
      },
      {
        "attributes": {
          "display": "Service Point",
          "OBJECTID": 13601
        },
        "geometry": {
          "x": -88.17557576699994,
          "y": 41.78393182000008
        }
      },
      {
        "attributes": {
          "display": "Service Point",
          "OBJECTID": 13602
        },
        "geometry": {
          "x": -88.17535967199996,
          "y": 41.78352876900004
        }
      },
      {
        "attributes": {
          "display": "Service Point",
          "OBJECTID": 13603
        },
        "geometry": {
          "x": -88.17534426199995,
          "y": 41.78340020400003
        }
      },
      {
        "attributes": {
          "display": "Service Point",
          "OBJECTID": 13649
        },
        "geometry": {
          "x": -88.17450698899995,
          "y": 41.78350136200004
        }
      },
      {
        "attributes": {
          "display": "Service Point",
          "OBJECTID": 13650
        },
        "geometry": {
          "x": -88.17435162999999,
          "y": 41.783597986000075
        }
      }
    ]
  }
];


var points1 = data.map((obj) => obj.features.attributes.display);
console.log(points1);

2
  • 2
    Because features is an array? Commented Dec 11, 2017 at 23:57
  • 1
    features are arrays, each object in array has attributes property. What are expected results? Commented Dec 11, 2017 at 23:57

1 Answer 1

1

Use another map on the features arrays. Really not clear what expected results are since some have no display and there are lots of duplicates

var points1 = data.map((obj) => obj.features.map(({attributes})=>attributes.display || "NONE"));
console.log(points1);
<script>
var data = [{
    "displayFieldName": "",
    "fieldAliases": {
      "OBJECTID": "OBJECTID"
    },
    "fields": [{
      "name": "OBJECTID",
      "type": "esriFieldTypeOID",
      "alias": "OBJECTID"
    }],
    "features": [{
        "attributes": {
          "OBJECTID": 649
        }
      },
      {
        "attributes": {
          "OBJECTID": 665
        }
      },
      {
        "attributes": {
          "OBJECTID": 762
        }
      }
    ]
  },
  {
    "displayFieldName": "",
    "fieldAliases": {
      "display": "display",
      "OBJECTID": "OBJECTID"
    },
    "geometryType": "esriGeometryPoint",
    "spatialReference": {
      "wkid": 4326,
      "latestWkid": 4326
    },
    "fields": [{
        "name": "display",
        "type": "esriFieldTypeString",
        "alias": "display",
        "length": 50
      },
      {
        "name": "OBJECTID",
        "type": "esriFieldTypeOID",
        "alias": "OBJECTID"
      }
    ],
    "features": [{
        "attributes": {
          "display": "Transformer",
          "OBJECTID": 1537
        },
        "geometry": {
          "x": -88.17602806699995,
          "y": 41.78431233100008
        }
      },
      {
        "attributes": {
          "display": "Transformer",
          "OBJECTID": 1591
        },
        "geometry": {
          "x": -88.17546081099994,
          "y": 41.783341919000065
        }
      }
    ]
  },
  {
    "displayFieldName": "",
    "fieldAliases": {
      "display": "display",
      "OBJECTID": "OBJECTID"
    },
    "geometryType": "esriGeometryPoint",
    "spatialReference": {
      "wkid": 4326,
      "latestWkid": 4326
    },
    "fields": [{
        "name": "display",
        "type": "esriFieldTypeString",
        "alias": "display",
        "length": 50
      },
      {
        "name": "OBJECTID",
        "type": "esriFieldTypeOID",
        "alias": "OBJECTID"
      }
    ],
    "features": [{
        "attributes": {
          "display": "Service Point",
          "OBJECTID": 13597
        },
        "geometry": {
          "x": -88.17599727899994,
          "y": 41.78465526100007
        }
      },
      {
        "attributes": {
          "display": "Service Point",
          "OBJECTID": 13598
        },
        "geometry": {
          "x": -88.17595382899998,
          "y": 41.78455803400004
        }
      },
      {
        "attributes": {
          "display": "Service Point",
          "OBJECTID": 13599
        },
        "geometry": {
          "x": -88.17582231499995,
          "y": 41.78435312600004
        }
      },
      {
        "attributes": {
          "display": "Service Point",
          "OBJECTID": 13600
        },
        "geometry": {
          "x": -88.17561004899994,
          "y": 41.784005335000074
        }
      },
      {
        "attributes": {
          "display": "Service Point",
          "OBJECTID": 13601
        },
        "geometry": {
          "x": -88.17557576699994,
          "y": 41.78393182000008
        }
      },
      {
        "attributes": {
          "display": "Service Point",
          "OBJECTID": 13602
        },
        "geometry": {
          "x": -88.17535967199996,
          "y": 41.78352876900004
        }
      },
      {
        "attributes": {
          "display": "Service Point",
          "OBJECTID": 13603
        },
        "geometry": {
          "x": -88.17534426199995,
          "y": 41.78340020400003
        }
      },
      {
        "attributes": {
          "display": "Service Point",
          "OBJECTID": 13649
        },
        "geometry": {
          "x": -88.17450698899995,
          "y": 41.78350136200004
        }
      },
      {
        "attributes": {
          "display": "Service Point",
          "OBJECTID": 13650
        },
        "geometry": {
          "x": -88.17435162999999,
          "y": 41.783597986000075
        }
      }
    ]
  }
];


</script>

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.