Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/480.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我的拼接方法会删除所有超过选定索引的对象?(javascript)_Javascript_Node.js - Fatal编程技术网

为什么我的拼接方法会删除所有超过选定索引的对象?(javascript)

为什么我的拼接方法会删除所有超过选定索引的对象?(javascript),javascript,node.js,Javascript,Node.js,代码: 节点: 那么,考虑到我的todo.findIndex正在工作,我的todo.splice出了什么问题?我设置了一个todo.findIndex测试,以显示它只找到索引3。因此,在todo.splice函数中,todo.findIndex也应该等于3,对吗?我试图减少被删除的项目数量,甚至完全删除这些项目。我不知道我做错了什么 3 [ { task: 'Free time', priority: 0 }, { task: 'Look for jobs', priority: 3 }

代码:

节点:

那么,考虑到我的todo.findIndex正在工作,我的todo.splice出了什么问题?我设置了一个todo.findIndex测试,以显示它只找到索引3。因此,在todo.splice函数中,todo.findIndex也应该等于3,对吗?我试图减少被删除的项目数量,甚至完全删除这些项目。我不知道我做错了什么

3
[
  { task: 'Free time', priority: 0 },
  { task: 'Look for jobs', priority: 3 },
  { task: 'Have a healthy relationship', priority: 2 }
]
[
  { task: 'Learn JS', priority: 1 },
  { task: 'Make dinner', priority: 0 },
  { task: 'Get sleep', priority: 2 }
]
1(要删除的项目数)添加到findIndex,而不是拼接。应该是这样。

1(要删除的项目数)添加到findIndex,而不是splice。应该是这样。
3
[
  { task: 'Free time', priority: 0 },
  { task: 'Look for jobs', priority: 3 },
  { task: 'Have a healthy relationship', priority: 2 }
]
[
  { task: 'Learn JS', priority: 1 },
  { task: 'Make dinner', priority: 0 },
  { task: 'Get sleep', priority: 2 }
]
// My delete function 
const deleteTodo = function (obj, title){
    return obj.splice(obj.findIndex(function (obj){
        return obj.task === title
    }), 1)
}