Search code examples
javascriptexpresshandsontable

Accessing json data from ajax using express.js


I'm pulling data from HandsOnTable and sending it to my Node.JS and Expess.JS backend for saving. As per the example here (http://docs.handsontable.com/0.20.2/tutorial-load-and-save.html) I'm doing a json.stringify on the data prior to sending it off via an AJAX GET.

My problem is in accessing the data once received on the backend. I'm using body-parser to access json objects like this: req.body.xxx; however I'd like to be able to access each row and field e.g. 'Bob'.

Any ideas? Below is my json data.

{"data":[["Bob",null,"PHD",null],["Julie",null,"test",null],["Stan",null,"Masers",null]]}

Solution

  • You can try following function to access data at specified row and column:

    function accessColumn(data, row, column) {
        return data.data[row][column];
    }
    console.log(accessColumn(data, 0, 0)); // "Bob"