Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function parseIntToScript(obj){
- //get all the keys in the object and build an aray.
- var keys = [];
- for(var key in obj){
- keys.push(key);
- };
- //condition loop caching
- var loopMax = keys.length;
- //loop over each key.
- for(var i=0; i<loopMax; i++){
- //get the object type.
- var thisType = typeof(globals[keys[i]]);
- //if type is string, check to see if it can be converted to a number.
- if(thisType === 'string'){
- //if parseInt returns a number, then convert.
- if(!isNaN(parseInt(globals[keys[i]]))){
- globals[keys[i]] = parseInt(globals[keys[i]]);
- }
- }
- //convert string arrays to int arrays.
- if(isArray(globals[keys[i]])){
- //loop through the array.
- var loopMax = globals[keys[i]].length;
- for(var j=0; j<loopMax; j++){
- if(!isNaN(parseInt(globals[keys[i]][j]))){
- globals[keys[i]][j] = parseInt(globals[keys[i]][j]);
- };
- };
- };
- };//loop
- function isArray(obj) {
- //returns true is it is an array
- if (obj.constructor.toString().indexOf('Array') == -1)
- return false;
- else
- return true;
- }//isArray
- };
Advertisement
Add Comment
Please, Sign In to add comment