I have an array of objects. Each object has, among others, an ID attribute. I want to find the index in the array of the object with a specific ID. Is there any elegant and simple way to do this in jQuery?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In the case you should use
forloop in javascript instead of using jQuery. See way 3 in http://net.tutsplus.com/tutorials/javascript-ajax/10-ways-to-instantly-increase-your-jquery-performance/UPDATED: jQuery is written in javascript and it can not be faster than another code written also in javascript. jQuery is very good if you work with the DOM, but doesn’t really help if you’re working with simple javascript arrays or objects.
The code you’re looking for can be something like this:
Important that you should hold some simple javascript rules: Always declare local variables (don’t forget
varbefore variable declaration) and cache any properties or indexes that you use more than one time in a local variable (likear.lengthabove). (See for example http://wiki.forum.nokia.com/index.php/JavaScript_Performance_Best_Practices)