Add property to javascript array

后端 未结 5 1727
不思量自难忘°
不思量自难忘° 2020-11-28 10:24

Arrays have a \"length\" property by default.

Can I add custom properties to them?

Without having to make them objects

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 11:05

    Yes. You can add them to the object by just declaring them and you can also extend Array using Array.prototype

    var j = new Array();
    j.yourprop = "foo";
    

提交回复
热议问题