10 examples of 'javascript create array of length n' in JavaScript

Every line of 'javascript create array of length n' 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
60function createArray(N) {
61 return Array.apply(null, { length: N }).map(Number.call, Number)
62}
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

27function array(n) {
28 for(i=0;i<n;i++) this[i]=0;
29 this.length=n;
30}
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}
144function makeArray (length) {
145 return fill(new Array(length), true)
146}
31function init_array(a, n, val){
32 var i;
33 for(i=0; i<n; ++i){
34 a[i] = val;
35 }
36}
257function createNodeArray(len) {
258 let arr = [];
259 while (len-- > 0)
260 arr.push(null);
261 let res = arr;
262 res.pos = 0;
263 res.end = 0;
264 return res;
265}
7function generate_n(rng: RandomGenerator, num: number): [number[], RandomGenerator] {
8 let cur: RandomGenerator = rng;
9 const out: number[] = [];
10 for (let idx = 0 ; idx != num ; ++idx) {
11 const [value, next] = cur.next();
12 out.push(value);
13 cur = next;
14 }
15 return [out, cur];
16}
106export function ones(n: number): number[] {
107 return filled(n, 1);
108}
8function zeros (n) {
9 return Array.apply(null, new Array(n)).map(function () { return 0.0; });
10}
71function generateArray(f, count) {
72 var slots = new Array(count);
73 for (var i = 0; i < count; ++i) {
74 slots[i] = f(i);
75 }
76 return slots;
77}

Related snippets