Build array of objects with specific column data

Build array of objects with specific column data

2008jackson2008jackson Posts: 38Questions: 9Answers: 0
edited September 7 in Free community support

Greetings. Variable below is required to build an array of objects with data from columns 1 and 6. With configuration below, a single array is built. Kindly assist.

var allData = this.api().cells(this.api().rows, [ 1,6 ]).data().toArray();

Output for above is ["ABCD", 1, "EFGH", 2, "IJKL",3]
Desired output is [{"ABCD", 1}, {"EFGH", 2}, {"IJKL",3}]

Answers

  • colincolin Posts: 12,600Questions: 0Answers: 2,154

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • 2008jackson2008jackson Posts: 38Questions: 9Answers: 0

    Hi Colin,

    Sorry about that. Test case available at http://live.datatables.net/nawudoba/8/edit

    Require to see the following array of objects in the console
    [
    {"Airi Satou", "Accountant"},
    {"Ashton Cox", "Junior Technical Author"},
    {"Cedric Kelly", "Senior Javascript Developer"},
    {"Tiger Nixon", "System Architect"},
    {"Tiger Nixon", "Accountant"}
    ]

  • kthorngrenkthorngren Posts: 13,773Questions: 25Answers: 3,242
  • 2008jackson2008jackson Posts: 38Questions: 9Answers: 0

    Thankyou for the answer Kevin. However, Im looking to export values of columns 0 and 1 not rows 0 and 1.

  • colincolin Posts: 12,600Questions: 0Answers: 2,154

    You can use columns().data() for that, so something like columns([0,1]).data().toArray()

    Colin

Sign In or Register to comment.