noon Array question
Hello all, quick question, lets say I have an array and I would like to get the modulo of that string, what would be the proper syntax to do something like that? can you call a % on a variable/array? something like var myArray = [5,16, 22, 26, 30]; for(i = 0; i < myArray.length; i++){ return myArray[i]; } modNum = myArray[i] % 5
I would like to get a new array with just the modulo of the myArray numbers. Any help would be appreciated, thanks!
Posted Sep 15, 2016, 4:42 PM UTC
04
Like this?
yes! exactly that. never seen .map will have to check that out
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
Look at some of the other array methods that do similar things too, like filter and foreach - each taking a function that runs for each element of the array.
really appreciate the help and links! thanks senocular.