我有一个数组。我想要在每个元素中添加一些字符 (:,\n
),以便在文本框中显示。
目前我的做法是:
$scope.source.arr = .... //This is an array
var actualText = "";
function func() {
$scope.source.arr.forEach(function(ele){
actualText += "***" + ele + " - \n"; //Adding necessary characters
})
}
var showText = function() {
func(); //Calling the function that populates the text as needed
var textBox = {
text : actualText;
...
}
}
有更好的方法来实现这个吗?
map
函数传递的函数将被调用数组中的所有项目,并收集从函数调用返回的所有值,并作为一个数组返回。该数组将与join
函数连接以获得单个字符串。 - thefourtheye