0

I have a few problem when I get all data from datatable jquery its not in array that I want.Below is my code,

var cells = [];
        var rows = $("#PtptnFileTblId_1").dataTable().fnGetNodes();
        for(var ii = 0; ii < rows.length;ii++)
        {   
            for(var i = 1; i < 15 ;i++){
              cells.push($(rows[ii]).find('td:eq('+ i +')').html());
            }
        }
        console.log(cells);

when I see the console log ,the data show like this :

["0000000000", "BP4", "99", "00987799201502", "SB1302BD2613", "911224126057", "Test1", "00791740", "zxa", "000000", "00000000", "null", "null", "10016020876162", "0000000000", "BP4", "59", "01678059201502", "MC1411BC8301", "940627146418", "Test2", "00672980", "qwq", "000000", "00000000", "null", "null", "12131023048090", "0000000000", "BP4", "13", "01482513201502", "SB1409BD7872", "910120126189", "Test3", "00672894", "AU", "000000", "00000000", "null", "null", "10016020934832"]

But the way I want is ,

[Array[15], Array[15], Array[15]
0:[Array[15]
    0:"0000000000"
    1:"BP4" 
    2:"99"
    3:"00987799201502" 
    4:"SB1302BD2613" 
    5:"12121312" 
    6:"TEST1" 
    7:"00791740"
    8:"zxa"
    9:"000000" 
    10:"00000000" 
    11:"null" 
    12:"null"
    13:"10016020876162"
2:[Array[15]
    0:"0000000000"
    1:"BP4" 
    2:"99"
    3:"00987799201502" 
    4:"SB1302BD2613" 
    5:"12121312" 
    6:"TEST1" 
    7:"00791740"
    8:"zxa"
    9:"000000" 
    10:"00000000" 
    11:"null" 
    12:"null"
    13:"10016020876162"
3:[Array[15]
    0:"0000000000"
    1:"BP4" 
    ......

Please anyone help me how I want to turn my code like the way I show above .This is my first time using jquery function like .push() .So is it any possible way.Any help will greatly appreciate.Thanks you

1 Answer 1

1

array.splice(0, 15) will take 15 elements from the array each time.

var arr = ["0000000000", "BP4", "99", "00987799201502", "SB1302BD2613", "911224126057", "Test1", "00791740", "zxa", "000000", "00000000", "null", "null", "10016020876162", "0000000000", "BP4", "59", "01678059201502", "MC1411BC8301", "940627146418", "Test2", "00672980", "qwq", "000000", "00000000", "null", "null", "12131023048090", "0000000000", "BP4", "13", "01482513201502", "SB1409BD7872", "910120126189", "Test3", "00672894", "AU", "000000", "00000000", "null", "null", "10016020934832"]

var result = [];

while(arr.length) {
    result.push(arr.splice(0,15));
}

console.log(result);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.