Lev Lev - 1 year ago 63
AngularJS Question

Angular creates a non native array

When I populate model.files directly in my view with

<input type="file" ng-model= vm.files[0]>
<input type="file" ng-model= vm.files[1]>

my vm.files looks like this (example A):

enter image description here

And I need like this (example B):

enter image description here

In order to obtain example B, I have to do
vm.files = new Array()
in my controller.

I would like to know the difference between the array in example A, and the array in example B ?

Are there 2 types of arrays in javascript ?

Answer Source

There are not "2 types of arrays" in JavaScript, and this is not "creating a non native array". It is creating an Object files with Properties 0 and 1. This is called Object Bracket Notation, and it occurs in Angular because Angular treats every property as an object unless it is defined otherwise ahead of time; You are correct that you need to use vm.files = new Array() to pre-allocate files as an array.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download