我正在使用Angular 2與Typescript。如何在Javascript對象數組中進行搜索?
我有一個看起來像這樣的對象數組;
lists: any [] = [
{title: 'Title1', content: 'Content1', id: 10},
{title: 'Title2', content: 'Content2', id: 13},
{title: 'Title3', content: 'Content3', id: 14},
{title: 'Title4', content: 'Content4', id: 16},
];
所有我想要做的是,我需要在數組中找到一個特定的ID後返回true或false值。
我找到了一個字符串示例如下。
myFunction() {
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var a = fruits.indexOf("Apple");
var d = a >= 0 ? true : false
console.log(d);
}
但是,當我在我的情況中應用這個,它沒有工作。
請告訴我們你的邏輯陣列中搜索對象。 –