How to use 'multidimensional array in jquery' in JavaScript

Every line of 'multidimensional array in jquery' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
12export function transformMultiDimArray(array: (string | string[])[], maxLength: number): string[][] {
13 const newArray: string[][] = array.map(row => {
14 if (row instanceof Array && row.length < maxLength) {
15 return row.concat(Array(maxLength - row.length).fill(''));
16 }
17 if (maxLength === 0 || maxLength === 1) {
18 return [row];
19 }
20 if (row instanceof String || typeof(row) === 'string') {
21 return Array(maxLength).fill(row);
22 }
23 return row;
24 });
25 return newArray;
26}
26function createNDimensionArray(multidimensional, dimensions, position, cb) {
27 var width;
28 var rest;
29 var newArray;
30 var i;
31 var currentDimension;
32 var returnValue;
33
34 if (dimensions.length > 0) {
35 width = dimensions[0];
36 rest = dimensions.slice(1);
37 newArray = [];
38 currentDimension = position.length - 1 - rest.length;
39 position[currentDimension] = 0;
40
41 for (i = 0; i < width; i++) {
42 newArray[i] = createNDimensionArray(multidimensional, rest, position, cb);
43 position[currentDimension]++;
44 }
45
46 returnValue = newArray;
47 } else {
48 if (typeof cb === 'function') {
49 returnValue = cb(position.slice(), multidimensional);
50 } else if (cb !== undefined) {
51 returnValue = cb;
52 } else {
53 returnValue = null;
54 }
55 }
56
57 return returnValue;
58}

Related snippets