Results 1 to 3 of 3

Thread: replace issues

Hybrid View

  1. #1
    Join Date
    May 2012

    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(" ");
    				var diff = unique(split);
    				document.getElementById("display").innerHTML = diff;
    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
    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:
    document.getElementById("display").innerHTML = diff.join(" ");

  3. #3
    Join Date
    May 2012

    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