我有一个定价数组

pricing = new Array();

pricing[1] = 35;
pricing[2] = 60;
pricing[3] = 84;
pricing[4] = 104;
pricing[5] = 120;
pricing[6] = 132;
pricing[7] = 140;
pricing[8] = 144;
pricing[9] = 153;
pricing[10] = 160;


低于10的所有事物都有价格,高于10的所有事物具有与十相同的价格

它只能达到20,所以我最初的工作只是重复价格11-20。但是那很浪费,我如何告诉我所有> 10 = 160的数组

附言:我对此的最终版本是压缩的:)

最佳答案

var pricing = [], i;
pricing.push(35);
pricing.push(60);
pricing.push(84);
pricing.push(104);
pricing.push(120);
pricing.push(132);
pricing.push(140);
pricing.push(144);
pricing.push(153);
for (i = 0; i < 11; i++) {
    pricing.push(160);
}


我为此也做了一个JSFiddle

@CD表示push function可以将多个项目附加到数组中。代码如下:

var pricing = [], value = 160;
pricing.push(35);
pricing.push(60);
pricing.push(84);
pricing.push(104);
pricing.push(120);
pricing.push(132);
pricing.push(140);
pricing.push(144);
pricing.push(153);
pricing.push(value, value, value, value, value, value, value, value, value, value, value);

09-18 17:59