Search code examples
javascriptjsonbootstrap-table

Cannot get a property of a Json-String


I get a Json-String from a table-API:

JS

var data = JSON.stringify($table.bootstrapTable('getSelections'));
console.log(data);

Output:

[{"name":"Chemical Entity Recogniser (ChER)","state":true}]

Now I want to get the value of "name". How do I do this?


Solution

  • You could directly use $table.bootstrapTable('getSelections')[0].name to get the name value

    or if you still want to use stringify, convert it into a JSON-string and fetch the name value from that you could do like this:

    var data = JSON.stringify($table.bootstrapTable('getSelections'));
    var obj = JSON.parse(data);
    console.log(obj[0].name);
    

    Output: Chemical Entity Recogniser (ChER)

    Hope this helps!