samedi 27 juin 2015

Convert Python string to array in JavaScript

I have a JavaScript script which receives information from a Python server. The Python server outputs a list, which is converted to a string prior to being sent to the JavaScript script.

I'd like to be able to convert the received string into a form that can be indexed with JavaScript. Here's an example output string from the Python server:

var Message = [['Word1A', 'Word1B'], ['Word2A', 'Word2B'], ['Word3A', 'Word3B']];

Given the above example, I'd like to be able to query the received string as as an indexed array:

var x;
for (x in Message) {
    alert(x[0]};

The above example should return:

Word1A
Word2A
Word3A

What's the best way to go about this?

Aucun commentaire:

Enregistrer un commentaire