Slicing from multidimensional arrays | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Slicing from multidimensional arrays

Hi Folks, how do you slice a value in a multidimensional array? A simple linear array is easy, i.e: Var names =['sean', 'weird al','daytona'] And then slicing the 2nd value: Var person =names.splice (1,1)[0]; But what if I had a multidimensional array as follows: Var characters =[['sean', 24,'blond'] , ['weird al', 45,'brunette'] ,[' daytona', 28, 'redhead']] And I wanted to slice age of the 2nd character and return it? As in slice 45 from Weird Al?

30th May 2017, 8:05 PM
Fungai Makawa
Fungai Makawa - avatar
5 Answers
+ 8
Surely [1][1] like he/she(Dunno gender) said And I think the splice you want would be like this,maybe var characters =[['sean', 24,'blond'] , ['weird al', 45,'brunette'] ,[' daytona', 28, 'redhead']]; characters = characters.splice(1,1)[0].splice(1,1)[0]; //characters = characters.slice(1,2)[0].slice(1,2)[0] alert(characters) Really long isn't it?
31st May 2017, 1:09 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 7
return characters[1][1]; what?
31st May 2017, 12:57 PM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 5
(I dunno too)
1st Jun 2017, 11:12 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 2
Ye it is
1st Jun 2017, 2:09 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
0
@very Hard(java &c++&....), curious, why the commented line? (btw- I'm a guy ;p )
1st Jun 2017, 10:56 AM
Fungai Makawa
Fungai Makawa - avatar