我试图通过一个数组循环。我有以下代码:
var currnt_image_list= '21,32,234,223';
var substr = currnt_image_list.split(','); // array here
我试图把所有的数据从数组。有谁能指引我正确的道路吗?
我试图通过一个数组循环。我有以下代码:
var currnt_image_list= '21,32,234,223';
var substr = currnt_image_list.split(','); // array here
我试图把所有的数据从数组。有谁能指引我正确的道路吗?
当前回答
试试这个:
$.grep(array, function(element) {
})
其他回答
使用jQuery的each()函数。
这里有一个例子:
$.each(currnt_image_list.split(','), function(index, value) {
alert(index + ': ' + value);
});
你可以使用for()循环:
var things = currnt_image_list.split(',');
for(var i = 0; i < things.length; i++) {
//Do things with things[i]
}
这里不需要jquery,只需要一个for循环即可:
var substr = currnt_image_list.split(',');
for(var i=0; i< substr.length; i++) {
alert(substr[i]);
}
试试这个:
$.grep(array, function(element) {
})
通过数组/字符串迭代的替代方法有副作用
Var STR = '21,32,234,223'; Var substr = str.split(','); Substr.reduce ((a,x)=> console.log('reduce',x), 0) //返回undefined 字符串的子串。Every (x=> {console.log(' Every ',x);返回true}) //返回true 字符串的子串。Some (x=> {console.log(' Some ',x);}) //返回false 字符串的子串。地图(x = > console.log(“地图”,x));//返回数组 Str.replace (/(\d+)/g, x=> console.log('replace',x)) //返回字符串