开发者

pass array from javascript function to another

I want to pass array from function to another in java script, but when I make it, the browser stalk, I don't know why . here's my code:

 function convertToBinary(decNumber){

            var copyDecNum=Number(decNumber);
            var binaryValues= new Array();
            var cnt=0;
               while(copyDecNum.value!=0)
            {
                binaryValues[cnt]=Math.floor(copyDecNum.value%2);
                copyDecNum.value=Math.floor(copyDecNum.value/2);
                cnt++;

            }
            binaryValues[cnt]=copyDecNum%2;
            viewResult(binaryValues,decNumber);



        }

        function viewResult(binaryValues,decNumber){

          alert("here"+binaryValues.length);           //here's the problem
          }

can som开发者_如何学Goeone help??


If you want to convert a decimal number to binary use the following,

var dec2bin = function (num) {
  return +(num.toString(2)) //convert number to binary string, then make that a number
}


Use copyDecNum instead of copyDecNum.value in your code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜