Skip to content

Instantly share code, notes, and snippets.

@bmarshall511
Created January 6, 2022 15:42

Revisions

  1. bmarshall511 created this gist Jan 6, 2022.
    21 changes: 21 additions & 0 deletions findindex.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    const items = {
    [
    id: 1,
    name: 'Ben'
    ],
    [
    id: 2,
    name: 'Angel'
    ],
    [
    id: 3,
    name: 'Robin'
    ]
    }

    // Find the index of name = 'Angel'.
    const index = items.findIndex(function(item) {
    return item.name === 'Angel'
    })

    // Returns: 1