SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Non-Member
    Join Date
    Jan 2008
    Location
    N43° 44.4824', W079° 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Add Array to string

    What am I doing wrong I want to add an Array to a string, but the alert won't write the array?
    Code JavaScript:
    var placestosee = ['newyork','people','laundry','stores'];
    alert('One place to see is the'+'placestosee[2]'+);

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,060
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Don't put the array element in quotes. You should also remove the + add the end, as it's invalid (comparable to me asking you "How much is 2 +" without ever finishing that sentence)

    Code javascript:
    alert('One place to see is the' + placestosee[2]);
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    Non-Member
    Join Date
    Jan 2008
    Location
    N43° 44.4824', W079° 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh, I see thank you. What about a space between the string and the array, currently the words are formed together.

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,060
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Just put in an extra space in the string right between the and '
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  5. #5
    Non-Member
    Join Date
    Jan 2008
    Location
    N43° 44.4824', W079° 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx, believe it or not that last problem was bothering me I couldn't figure it out.


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
  •