Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access a 2D array's range in JavaScript?

Given a 2D array, a[m][n] where m,n > 0, how do I access specific portions of that array (as I would in Matlab or Python, for example):

a[2:5][3:]

I realize that the slice() command works for one dimensional arrays but I can't get it to do what I want with higher dimensions.

Is this (easily) possible within Javascript?

like image 277
sdasdadas Avatar asked Oct 16 '25 14:10

sdasdadas


1 Answers

a.slice(2,3).map(function(m) {return m.slice(3);});

Assumes relatively up-to-date browser and/or shim.

like image 183
Niet the Dark Absol Avatar answered Oct 18 '25 11:10

Niet the Dark Absol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!