You haven't really told us what you are trying to do here, but I suspect you are mixing up objects, which use {}
and have property access like outerArray.middleArray1
, and arrays which are defined with []
and accessed by index: outerArray[0]
.
You example sort of works because assignments return the assigned value. This means something like:
middleArray1 = [
innerArray1 = ['data'],
innerArray2 = ['more data']
]
is the same as:
middleArray1 = [['data'],['more data']]
with the side effect that innerArray1
and innerArray2
get defined as global variables. For example:
outerArray = [
middleArray1 = [
innerArray1 = ['data'],
innerArray2 = ['more data']
],
middleArray2 = [
' ...more stuff...'
]
];
// log global variable innerArray1 (probably not what you want)
console.log(innerArray1)
// access ith index:
console.log(outerArray[0][0])
This is almost certainly not what you want. If you want to access data with properties like outerArray.middleArray1
, you need to define an object. For example:
// use {} to define object literal
outerArray = {
middleArray1: {
innerArray1: 'data',
innerArray2: 'more data',
},
middleArray2: ' ...more stuff...'
};
// now access by property name
console.log(outerArray.middleArray1.innerArray1)
Of course, you probably want to use a better naming convention for your properties…