javascript - Replace is not a function, no result -


no result on output textarea, on console log says, typeerror: newarr.replace not function, jsfiddle: http://jsfiddle.net/ehillanichole/woykv768/1/

$('#generatebutton').on('click', function(){         var arr = $('#input').val();             arr = arr.replace(/\n/g, ', ');             arr = arr.split(',');       var newarr = []; check = 0; count = 0;           for(i=0; i<arr.length; i++){           if(check != arr[i]){ count = 1; check = arr[i]; } else { count++; }           newarr.push(check + '.' + count);       }       newarr = newarr.replace(/, /g, '\n');         $('#output').val(newarr); }); 

my expected result is:

8000.1 8000.1 8000.2 8001.1 8001.2 8002.1 8003.1 8004.1 8004.2 8005.1 

note : mentioned in comments other fellow people, newarr array , array not have replace method.

you have update code from

newarr = newarr.replace(/, /g, '\n'); 

to

newarr = newarr.join().replace(/, /g, '\n'); 

for working version, please refer http://jsfiddle.net/woykv768/3/

for documentation, please refer http://www.w3schools.com/jsref/jsref_join.asp


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -