www.webdeveloper.com
Results 1 to 3 of 3

Thread: replace issues

  1. #1
    Join Date
    May 2012
    Posts
    8

    replace issues

    Hi I'm new here hopefully I can contribute as time goes on. I working on making a simple tag cloud for work and cant seem to get rid of the commas in my array.

    here's the code:
    HTML Code:
    <script type="text/javascript">
    var s = document.getElementById("input").value;
    				var punct_less = s.replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()]/g,"");
    				var finalString = punct_less.replace(/\s{2,}/g,"");
    				var split = new Array();	
    				split = finalString.split(" ");
    				split.sort();
    				var diff = unique(split);
    				document.getElementById("display").innerHTML = diff;
    </script>
    When it prints out it goes as such: orange,banana,apple,

    I tried a replace after the unique function that only displays non-duplicates but it doesn't seem to be working....any thoughts

  2. #2
    Join Date
    Aug 2007
    Posts
    3,767
    Code:
    split = finalString.split(" ");
    You're turning it into an array, so the default toString of an array is using commas to delimit entries. If you'd like spaces:
    Code:
    document.getElementById("display").innerHTML = diff.join(" ");

  3. #3
    Join Date
    May 2012
    Posts
    8

    Re: replace issues

    Thank that clear that up.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles