about_post_ids=about_post_ids.split(",");
就算是一个空值,也会被分割成一个数组,可以用alert(arr.lenght),测试;
如果是 ,1,2,3 或者 1,2,3, 或 , 都或生产一个空值。
空值的清除:
about_post_ids=$.grep(about_post_ids, function(n) {return $.trim(n).length > 0;})
或
about_post_ids = about_post_ids.filter(s => $.trim(s).length > 0);
查找数组中是否存在某值:
if(about_post_ids.indexOf('liangfang')===-1){//返回-1 表示找不到该值 about_post_ids.push('liangfang');//推送数组末尾一个值 }
数组的循环:
about_post_ids.forEach(function (ele,index,array) { //ele 是当前数组的值,index 是当前下标,索引值,key 值,array 原来的数值
console.log(ele+index);
}
除第一个参数,后面的可以选填