所以今天我有一个数组,里面有几个字符串,都以 结尾,例如:爵士,拉丁,恍惚,
我需要删除 , 数组中的最后一个元素。搜索Stackoverflow我找到了几个答案并尝试了下面的代码,但到目前为止没有运气:(
// How I'm generating my Array (from checked checkboxes in a Modal)
role_Actor = [];
$('.simplemodal-data input:checked').each(function() {
role_Actor.push($(this).val());
});
// roleArray = my Array
var lastEl = roleArray.pop();
lastEl.substring(0, lastEl.length - 1);
roleArray.push($.trim(lastEl));
// My function that displays my strings on the page
$.each(roleArray, function(index, item) {
$('.'+rowName+' p').append(item+', ');
});
// Example of the Array:
Adult Animated, Behind the Scenes, Documentary,
谢谢参观!
谢谢@克莱尔安东尼!修复!!!