所以今天我跟在他们几个字符串数组,全部采用,例如结尾:爵士,拉丁,恍惚,如何修剪掉最后一个字符数组 - jQuery的
我需要删除,关闭数组中的最后一个元素。搜索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,
感谢您抽空看看!
感谢@Claire Anthony!为修复!
为什么字符串在结尾处逗号开始?你应该修复你的数组生成过程。你确定逗号实际上是字符串的一部分,并且数组没有空的最后一个元素吗? – 2013-04-05 14:56:55
给出您正在修剪的示例数组 – theshadowmonkey 2013-04-05 15:00:10
这些字符串没有','与他们,但我必须添加它们以使显示的内容看起来正确。我已经添加了我的函数,它的作用如上 – 2013-04-05 15:00:12