Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JavaScript function: use: map function or forEach funtion. (with loops and if st

ID: 3679084 • Letter: J

Question

JavaScript function: use: map function or forEach funtion. (with loops and if statements) build a 2 dimension Array function so that you could evaluate le length of each values inside the Array (exemple: Array2d([t"apple",3], ["banana",41,[" peach",50]1)) with the function in the exemple Array2d(), you should be able to find the length of the string and number inside the array ex : Array2d[0][0] is "apple" so Array2d[0][0].length= 5 Array2d[1] [0] is "banana" . . Array2d[1] [0]. length = 6 Array2d[2] [0] is "peach" .. Array2d [2] [0].length = 5 its not a fixed Array size so it has the work as a general function and then do the same for the integers 3-1 char 4-1 char 50 = 2 char the number length is based on how much space it uses, I'm always getting problems with the fact that the 2 dimension Array could hold juste integers or String's and integers like in the exemple I wrote above. in the end I want to store my 2D Array in boxes based on the longest element in the category ex : + +-+ l applel 2 bananal 3 I peach 150 I juste looking for the 2D Array function that I could manipulate afterwards.

Explanation / Answer

Hi consider this following sample example that creates a 2D array for your reference,

This example creates an array with the following rows::

//

Each element in a JavaScript array can itself be an array giving the equivalent of a multi-dimensional array but the lengths of the arrays iyou add for the second dimension are not forced to be the same and so while you have one length for the first dimentsion of the array each of those elements has its own separate length for the second dimension and so on for as many more arrays within arrays as you build.

So if your array is:

var arry = [1
,[1,2,3]
,[1,2]
,[[1,2,3],[4,5,6]]
];

the length of the first dimension is arry.length which will return 4.

The length of the second dimension depends on which element of the first array you are referring to. The first element isn't an array and so doesn't have an array length. The second arry[1].length is 3 and the third and fourth arry[2].length and arry[3].length are both 2.

The last element of the array has a third dimension with both arry[3][0].length and arry[3][1].length being 3.

//

The following creates a chess board as a two dimensional array of strings. The first move is made by copying the 'p' in (6,4) to (4,4). The old position (6,4) is made blank.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote