SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: list to array

  1. #1
    SitePoint Zealot nicc9's Avatar
    Join Date
    Jan 2005
    Location
    New Orleans, LA
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    list to array

    hi, all.

    this might be a simple question, but I'm not really that familiar with JS besides some onmouseover FX:

    i got a list of strings separated by a comma. the text might contain accents as well, ex:

    HTML Code:
    wendy's, pizza mario, charles manson
    I need to turn this list into an array.

    how do I do that?

    thanks!

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you know the source of the text, you can simply use the split function.

    ie

    Code:
    var text = 'wendy's, pizza mario, charles manson';
    var arr = text.split(',');
    alert(arr.length);
    for(var i = 0; i < arr.length; i++)
        alert(arr[i]);


  3. #3
    SitePoint Zealot nicc9's Avatar
    Join Date
    Jan 2005
    Location
    New Orleans, LA
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ha! thanks... thought it had to be simple...


Bookmarks

Posting Permissions

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