score:1

Accepted answer

when a feature is created with the new feature({}) constructor, it does not look quite like the property-object put into the constructor. the properties you passed into the new feature will be stored under values of that feature.

the full properties of an ol-feature can be accessed via feature.getproperties() single values can be accessed via feature.get(key)

in your example, in data.map you named the first parameter name , which actually is the feature. this is a little bit confusing, i think feature or something similar would be a clearer variable name.

to get that features value, call name.get('name') (or feature.get('name')if you decide to rename the parameter)

also, the second argument of array.map is the index in the array, so in your case this will give you 0 and 1, which is fine if these are the values you want. if you want to get the id you can access these values by calling name.get('id') or feature.get('id') (see above). i guess i should mention the openlayers-functions feature.setid() and feature.getid(), just for completions sake.

tl;dr

try name.get('name')instead of name.name and check the results

score:1

use this instead (remove double-quotations):

 new feature({ id: 101, name: "abc" }), 
 new feature({ id: 102, name: "xyz" })

Related Query

More Query from same tag