javascript 在javascript中搜索对象数组
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 在javascript中搜索对象数组相关的知识,希望对你有一定的参考价值。
const newTodos = [
{
title: 'Buy Bread',
isDone: false,
},
{
title: 'Go to the Gym',
isDone: false,
},
{
title: 'Take a Shower',
isDone: false,
},
];
/*Find Method 1*/
const findTodo = function(myTodos: any, titleSearch: any) {
const titleReturned = myTodos.find(function(todo: any, index: any) {
return todo.title.toLowerCase() === titleSearch.toLowerCase();
});
return titleReturned;
};
/*Find Method 2*/
const findTodo = function(myTodos, titleSearch){
const indexReturned = object.indexOf(function(todo, index){
return todo.title.toLowerCase() === titleSearch.toLowerCase()
});
return indexReturned;
}
以上是关于javascript 在javascript中搜索对象数组的主要内容,如果未能解决你的问题,请参考以下文章