从二维码中检索数据并将其存储到数组中
Retrieving data from QR Code and storing it into an Array
var test = new Array("abc","def","ghi");
这个数组是二维码的输入数据。
function (result) {
alert("We got a barcode\n" +
"Result: " + result.text + "\n" +
"Format: " + result.format + "\n" +
"Cancelled: " + result.cancelled);
}
以上代码是从二维码中提取result
然而,从二维码中检索结果后,结果目前只是一串文本。
"abc, def, ghi"
有什么方法可以将它再次存储到数组中吗?
正如我在评论中提到的,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);
var test = new Array("abc","def","ghi");
这个数组是二维码的输入数据。
function (result) {
alert("We got a barcode\n" +
"Result: " + result.text + "\n" +
"Format: " + result.format + "\n" +
"Cancelled: " + result.cancelled);
}
以上代码是从二维码中提取result
然而,从二维码中检索结果后,结果目前只是一串文本。
"abc, def, ghi"
有什么方法可以将它再次存储到数组中吗?
正如我在评论中提到的,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);