从QR码检索数据并将其存储到数组中

时间:2016-06-06 03:35:08

标签: javascript arrays qr-code

var test = new Array("abc","def","ghi");

此数组是QR码的输入数据。

function (result) {
    alert("We got a barcode\n" +
                "Result: " + result.text + "\n" +
                "Format: " + result.format + "\n" +
                "Cancelled: " + result.cancelled);
    }

以上代码是从QR码中检索result

但是,从QR代码检索结果后,结果当前只是一个文本字符串。

"abc, def, ghi"

有什么办法可以将它再次存储到数组中吗?

1 个答案:

答案 0 :(得分:1)

正如我在评论中提到的,String.prototype.split将满足您的要求:

// A string with a comma and a space:
var str1 = "abc, def, ghi";
var array = str1.split(", ");
console.log(array);

// A string with just commas:

var str2 = "abc,def,ghi";
var array = str2.split(",");
console.log(array);