Which one is faster: iterating over a an array or an object. And what happens when i need to perform action such as deleting any element from in between?
var a = {"A1":1, "B1":2, "C1":3};
or
var a = ["A1", "B1", "C1"];
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.
Iterating over arrays should be faster than iterating over an object, but it’ll depend on:
On older browsers, removing elements from an array used to be very expensive (because it required changing the key on every subsequent element) but on modern browsers that’s less of a problem.
Seriously, just use whichever is the best representation for your project, and then worry about optimisation later if it becomes a problem.