Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite+ 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?
5 Réponses
+ 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?
+ 7
return characters[1][1];
what?
+ 5
(I dunno too)
+ 2
Ye it is
0
@very Hard(java &c++&....), curious, why the commented line? (btw- I'm a guy ;p )