turf.propReduce
What is turf.propReduce?
turf.propReduce folds every Feature's properties object into a single accumulator. It is the attribute-only counterpart to featureReduce.
turf.propReduce(geojson, callback, initialValue?) → anyThe callback receives (previousValue, currentProperties, featureIndex).
When would you use turf.propReduce?
Use turf.propReduce to build summaries that depend only on attributes — totalling a population property, collecting unique values of a category, or constructing an id-to-name lookup. Because geometry is ignored it is slightly faster and signals intent.
1const totalPopulation = turf.propReduce(
2 tracts,
3 (sum, props) => sum + (props.population ?? 0),
4 0
5);FAQs
How do I install Turf.js to use this function?
Install npm install @turf/meta and import with import { propReduce } from '@turf/meta', or use the umbrella @turf/turf bundle.
What if a Feature has null or missing properties?
The callback receives null for those. Use optional chaining (props?.key) or a fallback inside your reducer to stay safe.
Can I mutate the accumulator?
Yes — mutating a Map or array inside the reducer is fine for performance. Return the accumulator at the end of every iteration.
Should I use propReduce or loop the features array directly?
Both work. propReduce handles single-Feature and bare-Geometry inputs seamlessly, whereas looping requires guarding against those shapes. Use the Turf helper for robustness.