Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

find object from list

// main.dart

class Book {
  String id;
  String title;
  double price;

  Book(this.id, this.title, this.price);
}

void main() {
  final List<Book> _books = [
    Book('b1', 'A Blue Novel', 0.99),
    Book('b2', 'A Green Novel', 1.99),
    Book('b3', 'A Cooking Hanbook', 2.99),
    Book('b4', 'Kindacode.com', 0.00)
  ];

  // Find the index of the book whose id is 'b4'
  final int index1 = _books.indexWhere(((book) => book.id == 'b4'));
  if (index1 != -1) {
    print('Index: $index1');
    print('Title: ${_books[index1].title}');
  }

  // Find the index of the fist book whose title contains 'Novel'
  final int index2 = _books.indexWhere((book) => book.title.contains('Novel'));
  if (index2 != -1) {
    print('Index: $index2');
    print('Title: ${_books[index2].title}');
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: react: create form change state on input 
Javascript :: lastindexof 
Javascript :: use jquery in project using NPM 
Javascript :: jest cannot find module 
Javascript :: javascript swap 
Javascript :: data table in angular 8 from api 
Javascript :: Add array to formData react js 
Javascript :: Error: Node Sass version 5.0.0 is incompatible with ^4.0.0 
Javascript :: create cookie javascript react 
Javascript :: unzip array javascript 
Javascript :: js number round to each 15 
Javascript :: insert a line break into a text component in react-native 
Javascript :: how to reverse array in javascript 
Javascript :: sum of two array in javascript 
Javascript :: run file with nodemon 
Javascript :: axios js 
Javascript :: javascript copy object 
Javascript :: konva line thickness 
Javascript :: javascript remove function from object 
Javascript :: nuxt auth user info 
Javascript :: sort array based on multiple columns javascript 
Javascript :: create a customer in stripe node.js 
Javascript :: javascript function add two numbers 
Javascript :: find multiples of a number 
Javascript :: sort object properties by value javascript 
Javascript :: django csrf failed ajax case 
Javascript :: javascript check undefined or null 
Javascript :: object.keys javascript 
Javascript :: how to click on alret dialog with pupeteer 
Javascript :: javascript return value from async function 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =