What I do in php:
$arr = [1=>'a', 3=>'b', 2017=>'zzzzZZZZ'];
What I konw in js:
var arr = [];
arr[1] = 'a';
arr[3] = 'b';
arr[2017] = 'zzzzZZZZ';
Your code would make an array of length 2018 since the largest array index defined is 2017 and the remaining undefined elements are treated as undefined.
var arr = [];
arr[1] = 'a';
arr[3] = 'b';
arr[2017] = 'zzzzZZZZ';
console.log(arr.length, arr);
var obj = {
1 : 'a',
3 : 'b',
2017 : 'zzzzZZZZ'
}
var obj = {
1: 'a',
3: 'b',
2017: 'zzzzZZZZ'
}
console.log(obj);
Refer : javascript Associate array
obj.1 to get the value but obj[1] or obj['1']. Seems that JS object stores data as array, and the most basic way to fetch data is also array. In the meanwhile, array act like restricted object.