Javascript – Add a property to a JavaScript array


Arrays have a "length" property by default.

Can I add custom properties to them?

Without having to make them objects.

Best Solution


var arr = [1,2,3,4,5];
arr.prop = 'value';

Arrays are already objects in JavaScript -- they just have some extra features and a special literal syntax.