Jump to content

Can't Apply Object.defineproperty To An Array.length


graduate

Recommended Posts

Hello, It is my first message on this forum and I'm currently learning JavaScript. When I try this code

var a = [1,2,3];Object.defineProperty(a, 'length', {value:10, writable:false});

I get an error from Firebug - "defining the length property on an array is not currently supported". I've read in the fresh 6th edition of "Java Script" book of David Flanagan that I can make a length property of an array unwritable with Object.defineProperty method, but I get the same error from Firebug when I try to apply this method a to change any property (value, writable etc.).

Link to comment
Share on other sites

You can't modify the length property of an array. It doesn't make logical sense. If an array has 5 elements and you set the length to 3, you've messed up the whole structure.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...