DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • prototype
    • concat
    • forEach
    • indexOf
    • join
    • pop
    • push
    • replace
    • reverse
    • shift
    • slice
    • splice
    • unshift
  • static
    • can.List.Map
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • can.List
  • /
  • indexOf
  • / On this page
    • indexOf

      function

      Look for an item in a List.

      • source

      list.indexOf(item)

      indexOf finds the position of a given item in the List.

      Parameters

      1. item {*}:

        the item to find

      Returns

      {Number}:

      the position of the item in the List, or -1 if the item is not found.

      var list = new can.List(['Alice', 'Bob', 'Eve']);
      list.indexOf('Alice');   // 0
      list.indexOf('Charlie'); // -1
      

      It is trivial to make a contains-type function using indexOf:

      function(list, item) {
          return list.indexOf(item) >= 0;
      }
      

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.