Skip to content

Instantly share code, notes, and snippets.

@infinitbility
Created July 12, 2020 14:05
Show Gist options
  • Select an option

  • Save infinitbility/ba0f69d4d519cac89744a1e805e0f6fe to your computer and use it in GitHub Desktop.

Select an option

Save infinitbility/ba0f69d4d519cac89744a1e805e0f6fe to your computer and use it in GitHub Desktop.

Revisions

  1. infinitbility created this gist Jul 12, 2020.
    10 changes: 10 additions & 0 deletions javascript-indexOf.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    //indexOf example
    var fruits = ['Banana', 'Blackcurrant', 'Blueberry', 'Chili pepper', 'Cranberry', 'Eggplant', 'Gooseberry'];

    // You get their index ( Key )
    var index = fruits.indexOf('Blueberry');
    // output 2

    // if value not available
    var index = fruits.indexOf('Apple');
    // output -1