Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have a javascript that contains an array...
var myArr = new Array(10);This array hold decimal values of characters that I need to assign to another variable, a string.
How do I get the variables from integers(?) to characters while still being able to assign them into an array?
Thanks!
Sara

Hi Sara,
You can use parseFloat(myArray[n]); to convert a string to a decimal. Javascript treats the intial value assigned to the variable as a string, if I am not mistakened. So you can just reassign values of variables (since they are already treated as strings) to other variables with no problem.
You can observe this behavior if you try and do the following.
var myArray = new Array(4);
myArray[0] = "Hi";
myArray[1] = "21.222222";
myArray[2] = "21";
// variable declarations.document.writeln(myArray[0] + "<br/>");
document.writeln(myArray[1] + myArray[2] + "<br/>");
document.writeln(parseFloat(myArray[1]) + parseFloat(myArray[2]) + "<br/><br/>");
// example of concatenation and actual addition.
// you can use parseInt() instead of parseFloat().document.writeln("myArray[0] before: " + myArray[0] + "<br/>");
document.writeln("myArray[1] before: " + myArray[1] + "<br/><br/>");
// initial variable assignment values.myArray[0] = myArray[1];
myArray[1] = myArray[2];
// variable value reassignment.document.writeln("myArray[0] after: " + myArray[0] + "<br/>");
document.writeln("myArray[1] after: " + myArray[1] + "<br/>");
// new values after value reassignment.Of course, you can also use parseInt() to truncate decimal values or convert any kind of string to an integer value. Did this answer your question?
- Rolos

I took her question to mean that the array holds decimal values (ASCII codes) for individual characters.

Thanks for the responses and comments.
Don is right, I am trying to get decimal values into their character equivalents to form a string that can be assigned to a variable later in the code.
Thanks.
Sara

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |