Find Index

Find the index of the first element matching a condition.

Code

General
arr.find_index { |item| item['id'] == targetId } || -1

Parameters

Array

ID to find

Server

More Ruby Snippets