开发者

What is the best way to have an array of 2 properties?

I'd like to have an array in javascript that each item contains 2 properties instead of 1, how would that be possible?

The following only adds one property to the item by default:

var headerCellWidths = new Array();
headerCellWidths.push(100);

this enables me access the item using [0][normalCellWidth]

but I'd like t开发者_JAVA技巧o be able to have e.g. [index][normalCellWidth][firstTemplateCellWidth]

e.g. [0][100][25]

e.g. headerCellWidths.add(100, 25);

One solution is to create my own CustomArray obviously which maintains 2 separate array instances but isn't there a better way?

Thanks,


You can add the entries as objects to the array. Try this:

 headerCellWidths.push({normalCellWidth:100, firstTemplateCellWidth:25);

You would access the items using:

headerCellWidths[0].normalCellWidth and headerCellWidths[0].firstTemplateCellWidth

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜