9 examples of 'javascript create array with n elements' in JavaScript

Every line of 'javascript create array with n elements' 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
this disclaimer
27function array(n) {
28 for(i=0;i<n;i++) this[i]=0;
29 this.length=n;
30}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

60function createArray(N) {
61 return Array.apply(null, { length: N }).map(Number.call, Number)
62}
31function init_array(a, n, val){
32 var i;
33 for(i=0; i<n; ++i){
34 a[i] = val;
35 }
36}
274function ARRAY(aElements, aParts) {
275 var aResult = [];
276
277 aElements.forEach(function(fnArgument, i) {
278 aResult[i] = fnArgument(aParts);
279 });
280 return aResult;
281}
669function fillArray(_n, _i, arr) {
670 while(true) {
671 var i = _i;
672 var n = _n;
673 var l = n.left;
674 var v = n.key;
675 var r = n.right;
676 var next = l !== null ? fillArray(l, i, arr) : i;
677 arr[next] = /* tuple */[
678 v,
679 n.value
680 ];
681 var rnext = next + 1 | 0;
682 if (r !== null) {
683 _i = rnext;
684 _n = r;
685 continue ;
686 } else {
687 return rnext;
688 }
689 };
690}
43constructor(n) {
44 super();
45 this.fields = new Array(n);
46}
64function fillArray3D<T>(
65 a: T[][][],
66 dimension1: number,
67 dimension2: number,
68 dimension3: number,
69 value: T,
70) {
71 for (let i = 0; i < dimension1; i++) {
72 a[i] = [];
73 for (let j = 0; j < dimension2; j++) {
74 a[i][j] = [];
75 for (let k = 0; k < dimension3; k++) {
76 a[i][j][k] = value;
77 }
78 }
79 }
80}
1215function createFloatArray(N) {
1216 if (typeof Float32Array === "undefined") {
1217 var r = new Array(N);
1218 for (var i = 0; i < r.length; i++) {
1219 r[i] = 0.0;
1220 }
1221 }
1222 return new Float32Array(N);
1223}
312function ARRAY(aElements, aParts) {
313 return aElements.map(function (fnElement) {
314 return fnElement(aParts);
315 });
316}

Related snippets