日期:2014-05-16  浏览次数:20341 次

array 数组改变值的问题。求大侠指点。
如题: var array=new Araay(["3","3","6","6","9","11"]); 把array的值从1开始改值排序 为[1,1,2,2,3,4] 序号可以重复但不能间断 !

------解决方案--------------------
JScript code

function test(){
        var array=["3","3","6","6","9","11"]; 
        var arr = [];
        var index = 1;
        for(var i=0; i<array.length;i++){
            if(i==0){
                arr[i] = index;
            }
            else{
                if(array[i]==array[i-1]){
                    arr[i] = index;
                }
                else{
                    index = index +1;
                    arr[i] = index;
                }
            }
        }
        alert(arr);
    }