[英]pass an array in a function to string JavaScript
I have the following problem with the following code: When I pass the Array to "track" I always get an error, I think it may be because an object is being passed and a String, but I'm not sure and I can't check it.以下代码存在以下问题:当我将数组传递给“跟踪”时,我总是收到错误消息,我认为这可能是因为正在传递一个对象和一个字符串,但我不确定,我不能检查它。
for (var i = 0; i < data.twKeyword.length; i++){
var stream = client.stream('statuses/filter', {track: data.twKeyword[i]});
}
I have tried:我试过了:
data.twKeyword
data.twKeyword[i]
And none of these options has given me a positive result.这些选项都没有给我带来积极的结果。
He creado una variable nueva a la que le he ido pasando los valores del Array: He creado una variable nueva a la que le he ido pasando los valores del Array:
var x1 = JSON.stringify(data.twKeyword[i].name);
Después como estos valores se mostraban con doble comillas (""), he utilizado el siguiente código para eliminarlas: Después como estos valores se mostraban con doble comillas (""), he utilizado el siguiente código para eliminarlas:
x1.replace(/['"]+/g, '')
El código ha quedado así, y funciona: El código ha quedado así, y funciona:
for (var i = 0; i < data.twKeyword.length; i++){
var x1 = JSON.stringify(data.twKeyword[i].name);
var stream = client.stream('statuses/filter', {track: x1.replace(/['"]+/g, '')});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.