开发者

pass array from javascript function to another

开发者 https://www.devze.com 2023-02-17 06:58 出处:网络
I want to pass array from function to another in javascript, but when I make it, the browser stalk, I don\'t know why . here\'s my code:

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

精彩评论

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