Skip to content
Advertisement

Best practice/way to get value where id = something on a list of dictionaries

I have the following list of dictionaries:

JavaScript

I would like to get the value where id = xxxxxxxxxxxx.

Which would be the fastest way?

Advertisement

Answer

One possible solution is to use next() built-in method:

JavaScript

Prints:

JavaScript

Or: If you search multiple times, it’s worth considering transforming the list to dictionary:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement