Dobre! Go to the point! Is this such a code not working ??
var count = 5; var arr[count] = 'blabla'; In PHP, such a focus is quite possible and easy, but what about Javascrypt ???
Dobre! Go to the point! Is this such a code not working ??
var count = 5; var arr[count] = 'blabla'; In PHP, such a focus is quite possible and easy, but what about Javascrypt ???
Initialize the variable first explicitly ...
var count = 5; var arr = []; arr[count] = "blahblah"; With objects as associative arrays, also:
var arr = {} arr["key"] = "value"; Unlike PHP, in JavaScript it is necessary to declare variables before using them. This is what the var keyword is used for. It allows you to initialize variables, but it is important to understand that assigning values to an array element is not the initialization of an array. Therefore, the correct option:
var arr = []; arr[count] = 'blabla'; PS
What kind of stupid argument " in PHP such a focus is quite possible and easy "? PHP is not JavaScript, it is logical that their syntaxes are different.
Source: https://ru.stackoverflow.com/questions/331195/
All Articles