locked
How to change array separator using jquery RRS feed

  • Question

  • User1839056048 posted

    Hi,

    in my application on the click event of check box ,i want add particular value to array

    here is the code

      var ids = [];
                  $('body').on('click', '.chkbox', function () {
    
    
    var jj = $(this).closest('tr').children('td');
                      var bb = jj.eq(5).text();
                      ids.push(bb);
    
    });

    this is working fine

    my requirement is to change the array separator. now it is comma.

    i want to change to semicolon

    normally my array returns like this

    jain-1,0,0,1,baiju-0,1,0,0

    this is 2 elements in the array

    i need the above to be like this

    jain-1,0,0,1;baiju-0,1,0,0

    i change a semicolon between 1 and baiju

    how it is possible

    Regards

    Baiju

    Thursday, February 25, 2016 1:36 PM

Answers

  • User475983607 posted

    Use the JavaScript array.join() method to convert an array to a delimited string.

    <script type="text/javascript">
    
        function arrayTest() {
            var fruits = ["Banana", "Orange", "Apple", "Mango"];
    
            var csvStr = fruits.toString();
            console.log(csvStr);
            //Banana,Orange,Apple,Mango
    
            var ssvStr = fruits.join(";");
            console.log(ssvStr);
            //Banana; Orange; Apple; Mango
    
        }
    </script>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 25, 2016 4:22 PM