为什么splice方法返回undefined并且不删除以下代码中位置4的元素:
var excludedDepartmentsList = [1, 2, 3, 4, 5, 6];
var currentDepartmentId = 5;
var position = $.inArray(currentDepartmentId, excludedDepartmentsList);
if (position > -1) {
var q = excludedDepartmentsList.splice[position, 1];
return;
}
Run Code Online (Sandbox Code Playgroud)
我在这里做了一个测试:http://jsfiddle.net/PnVEb/
Sel*_*gam 13
.splice是一个函数,它应该被调用,excludedDepartmentsList.splice(position, 1)而不是excludedDepartmentsList.splice[position, 1].请注意括号从更改[]为().
使用()如下,它应该返回5
excludedDepartmentsList.splice(position, 1)
Run Code Online (Sandbox Code Playgroud)
固定小提琴: http ://jsfiddle.net/PnVEb/1/
| 归档时间: |
|
| 查看次数: |
552 次 |
| 最近记录: |