SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: jQuery and array question

  1. #1
    SitePoint Enthusiast zlaajaa's Avatar
    Join Date
    Feb 2005
    Location
    home?
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery and array question

    Hi everyone,

    I have array with elements like this:
    113:12,
    1125:36,
    1125:39,
    1123:26
    and I need somehow to get result like this(string):
    113:12;1125:36,39;1123:26 can somebody please help?

    Thanks

  2. #2
    Unobtrusively zen silver trophybronze trophy
    SitePoint Award Recipient paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,233
    Mentioned
    42 Post(s)
    Tagged
    2 Thread(s)
    Code javascript:
    var array = [
        '113:12',
        '1125:36',
        '1125:39',
        '1123:26'
    ];
    var string = array.join(';');
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast zlaajaa's Avatar
    Join Date
    Feb 2005
    Location
    home?
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for reply.. but what I really need is:
    Code JavaScript:
    var array = [
        '113:12',
        '1125:36',
        '1125:39',
        '1123:26'
    ];

    to get
    Code JavaScript:
    var array = [
        '113:12',
        '1125:36,39',
        '1123:26'
    ];

    in first array, if I have more elements like '1125:36','1125:32','1125:46','1125:39' I would need to have '1125:36,32,46,39' I guess I have to use some loop.. or something to get result like that

    Thanks

  4. #4
    Unobtrusively zen silver trophybronze trophy
    SitePoint Award Recipient paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,233
    Mentioned
    42 Post(s)
    Tagged
    2 Thread(s)
    For what purpose do you require it for?

    There is a more standards-based approach to the situation as a JSON object:

    Code:
    {
        113 : [12],
        1125 : [36, 39],
        1123 : [26]
    };
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

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
  •