当我使用console.log()函数加入该数组时,它将返回合并后的数组,但是当我在console.log()之外使用.join()函数时,则不会合并该数组。如何在console.log()之外结合使用此数组以创建没有逗号的单个字符串?
var string = stringArray.map(string => "&sources=" + string);
console.log(stringURL.join(''));
stringURL.join('');
console.log(stringURL);
答案 0 :(得分:3)
.join()
是一个返回联接字符串的函数。因此,当您调用它时,它将计算该值,然后将其返回。
将其存储在变量中。
var joinedString = stringURL.join('');
答案 1 :(得分:1)
您的问题是 stringURL.join(''); 确实修改了stringURL但提供了新的字符串。所以最好是做
var mappedString = stringArray.map(string => "&sources=" + string);
console.log(mappedString.join(''));
var joinedString = mappedString.join('')
console.log(joinedString);
答案 2 :(得分:-1)
您不能有一个名为string的变量名,它是受保护的。将其更改为其他内容,它将起作用。
Here's a complete list of reserved keywords和here is an explanation from Mozilla MDN
#create yield
def generatorSendData():
for index, row in actions.iterrows():
yield {
"_index": "megacorp",
"_type": "employee",
"_source": row.to_json()
}
#generator
valueGenerator=generatorSendData()
result_gen= helpers.streaming_bulk(es, actions=valueGenerator)
for success, result in result_gen:
print success, result
那应该做!