Skip to content

Instantly share code, notes, and snippets.

@IlmariKu
Created March 18, 2021 11:37
Show Gist options
  • Save IlmariKu/c89d8fa474907e1c623a00c2792bf859 to your computer and use it in GitHub Desktop.
Save IlmariKu/c89d8fa474907e1c623a00c2792bf859 to your computer and use it in GitHub Desktop.
Loop unknown amount of nested Javascript arrays and convert all found values to something else.
// I used this function to find nested geoJson float values and round the values up to smaller decimals
function loopArray(nestedArrays) {
return nestedArrays.map(arrayNow => {
if (isArray(arrayNow)) {
return loopArray(arrayNow)
} else if (isNumber(arrayNow)) {
return 'your operation here'
}
})
}
const convertedArray = loopArray(unknownNestedArray)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment