A
A
Alexey2015-05-27 16:37:44
JavaScript
Alexey, 2015-05-27 16:37:44

The simplest array creation in JavaScript?

The situation after PHP in the field of creating an array became rather incomprehensible.
Previously, I could apply to an example in a loop:
arr[number] = response;
Where, number - will be any number, for example 1000 or 1350.
How to create such an array in JavaScript?
For example:

var images = []; 
images[number] = response;

If number is 20, it doesn't create it and the array is left empty. In this case, number can be 130, etc.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Igor, 2015-05-27
@azovl

Use objects instead of arrays.

var images = {};
images[number] = response;

Z
Zhenya, 2015-05-27
@kotova_web

https://learn.javascript.ru/data-structures
Probably the best tutorial I've ever seen, find about arrays, everything is super clear

D
Daniil Kolesnichenko, 2015-05-27
@KolesnichenkoDS

What's the problem?

var images = []; // []
images[130] = "hello, world"; // [undefined x 130, "hello, world"]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question