如何从数组中获取所有字符串,遍历它们,然后执行所有字符串的函数Ex。
var array = ["Congrats!", "Sorry you failed"]
responses.get(array).function
// I want it to basically do is responses.get("Congrats!").function
// and responses.get("Sorry you failed").function both but simpler
答案 0 :(得分:0)
您可能想要Array.prototype.map()
var array = [ 'Congrats!', 'Sorry you failed' ]
array.map( console.log )
// Output:
// Congrats! 0 ["Congrats!", "Sorry you failed"]
// Sorry you failed 1 ["Congrats!", "Sorry you failed"]
array.map( function( str ) { console.log( str ) } )
// Output:
// Congrats!
// Sorry you failed