Linked Questions

-3 votes
2 answers
10k views

i have a number 10 how to convert to this to number array in java script. answer should be [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] OR How to convert number(10) to number of items in array in javascript
Santhosh's user avatar
  • 1,089
7 votes
1 answer
372 views

In most javascript apps I usually declare an array like so var x = []; but I've seen a ton of example code on MDN that take this approach instead var x = new Array(10); With V8/other modern JS ...
Toran Billups's user avatar
-1 votes
1 answer
271 views

How to create an array with length 3 and the value for the array element is 0. if i give the length of the array as 3, then the array should be like below a[0]=0; a[1]=0; a[2]=0; I have tried ...
user3326265's user avatar
0 votes
2 answers
184 views

Im using Angular 8 and Typescript Problem: i want an array to have the same length as the music source of an audio tag, to enable comments that are synchronized with the intended location in the track....
DuB loxx's user avatar
  • 235
2478 votes
81 answers
2.8m views

I'm looking for any alternatives to the below for creating a JavaScript array containing 1 through to N where N is only known at runtime. var foo = []; for (var i = 1; i <= N; i++) { foo.push(i)...
Godders's user avatar
  • 25.3k
890 votes
24 answers
434k views

In Perl I can repeat a character multiple times using the syntax: $a = "a" x 10; // results in "aaaaaaaaaa" Is there a simple way to accomplish this in Javascript? I can obviously use a function, but ...
Steve's user avatar
  • 55.8k
165 votes
9 answers
280k views

in javascript how would I create an empty array of a given size Psuedo code: X = 3; createarray(myarray, X, ""); output: myarray = ["","",""]
gus's user avatar
  • 1,808
224 votes
6 answers
65k views

Are trailing commas standard in JavaScript, or do most browsers like Chrome and Firefox just tolerate them? I thought they were standard, but IE8 puked after encountering one—of course IE not ...
Adam Rackis's user avatar
  • 83.5k
131 votes
4 answers
17k views

I've run into the following code in the es-discuss mailing list: Array.apply(null, { length: 5 }).map(Number.call, Number); This produces [0, 1, 2, 3, 4] Why is this the result of the code? What's ...
Benjamin Gruenbaum's user avatar
27 votes
3 answers
25k views

Why are TypedArrays not as fast as regular arrays? I want to store some precalculated integer values, and I need the access to the array to be as fast as it can be. http://jsperf.com/array-access-...
Sukhanov Niсkolay's user avatar
16 votes
10 answers
21k views

We dont use for loop in functional programming, instead, we use higher order functions like map, filter, reduce etc. These are fine for iterating through an array. However, I wonder how do I do a ...
Kayote's user avatar
  • 15.8k
15 votes
3 answers
63k views

Say I have a number 18, instead of an array, in hand. What is the best way to create a functional loop in JS given a number X instead of array of X elements? I can do this: [1,2,3].forEach(function(...
Alexander Mills's user avatar
8 votes
3 answers
7k views

I have an array declared as var arr = new Array(); Then i have an array of objects which are returned by Server. And each object in this array has three fields(always). I have to loop through this ...
aneeshere's user avatar
  • 569
4 votes
5 answers
5k views

Say I have an array : var newArray = []; I can add strings to it like so : var thisString = 'watch'; newArray.push(thisString); What I want to do is have an array of this string. So, for example, I ...
thatOneGuy's user avatar
  • 10.7k
2 votes
3 answers
10k views

It's simple, i want to add an undefined element to an array, lets say i have an array Punkt and i have punkt[0] = x: 15, y:"16s" . As i know for ex. the element will have 4 punkt in total i want to ...
Faarbhurtz's user avatar

15 30 50 per page