Accessing every nth element of all arrays in multidimensional array

Hi,

I wanted to manipulate/change the value of every nth value of all arrays in a multi dimensional array without creating a function. It would be something like the below but I am unsure if I can only write a looping function to achieve this in JavaScript.

let arr1 = [[1,2,3],[2,4,6],[10,20,30]];
let arr2 = [arr1[all indexes][2]*5]

If someone knows the answer please let me know.

The way you wrote it could be adjusted to work in Python via list-comprehension. However I don’t think something like that exists for JavaScript.

What does exist are loops, particularly for-loops would be suited for this kind of task.

I’m not 100% sure what you’re trying to describe, but you would probably want to do this with a loop. Possibly you could do it with a map(), but that depends on what your goal is.

Yes, I think you are correct. I was trying use something similar to how Python arrays function but looks like it might be necessary to use a for-loop. Thanks!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.