www.webdeveloper.com
Results 1 to 3 of 3

Thread: Array conversion issue

  1. #1
    Join Date
    Apr 2011
    Posts
    8

    Array conversion issue

    Hello friends,

    I am trying (in Javascript an Coldfusion) to convert: {"val1":"member","val2":"book","val3":"journal","val4":"new_member","val5":"cds"},
    into this: { member,book,journal,new_member,cds}

    Notice that I am trying to eliminate quotes.

    Is it possible to achieve that? How can I do it?

    Thanks
    Tom

  2. #2
    Join Date
    Sep 2007
    Posts
    301
    I am trying this:

    Code:
      
    <script type="text/javascript">
    
    // http://www.webdeveloper.com/forum/showthread.php?t=260748
    
    var A = {
    "val1":"member",
    "val2":"book",
    "val3":"journal",
    "val4":"new_member",
    "val5":"cds"
    }
    
    //  http://www.w3schools.com/json/json_intro.asp
    //  http://www.w3schools.com/json/json_syntax.asp
    //  http://www.w3schools.com/json/tryit.asp?filename=tryjson_eval
    //  http://www.w3schools.com/jsref/jsref_toSource_date.asp
    
    alert(A.toSource());  // ({val1:"member", val2:"book", val3:"journal", val4:"new_member", val5:"cds"})
    
    var txt = '{'+A.val1 + ',' + A.val2 + ',' + A.val3 + ',' + A.val4 + ',' + A.val5 + '}'
    
    alert (  txt  );  // { member,book,journal,new_member,cds} 
    
    var txt = '{'+A.val1 + ',' + A.val2 + ',' + A.val3 + ',' + A.val4 + ',' + A.val5 + '}'
    
    alert (  txt  );  // { member,book,journal,new_member,cds} 
    
    //  txt = txt.replace(/"/g,"");
    
    //  alert(txt);
    
    var txt = '{'+A.val1 + ': "z&#252;lkarneyn" ,' + A.val2 + ':4,' + A.val3 + ':2016,' + A.val4  + ':"s&#252;leyman",' + A.val5 + ':2022 }'; 
    
    var A = eval ("(" + txt + ")");  
    
    alert( A );
    alert(A.toSource());
    
    alert(A.member); // z&#252;lkarneyn
    alert(A.book);   // 4
    alert(A.journal);  // 2016
    alert(A.new_member); // s&#252;leyman
    alert(A.cds); // 2022
    
    </script>
    İyiliği emret. Kötülükten alıkoy. (31/16)

    hasbunallahuVeNimelVekil++

  3. #3
    Join Date
    Apr 2011
    Posts
    8
    Thank you for your reply. The "toSource()" doesn't work in IE.
    Thank you again
    Tom

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