Skip to content

Instantly share code, notes, and snippets.

@netpoetica netpoetica/enumerate.js
Last active Aug 29, 2015

What would you like to do?
enumerate - decompose an array for iteration in a
// You have an array
var myArr = ["a", 'b', "c"];
// You want to enumerate through it w/ specified index. If you enumerate
// through an array by default index cannot be "guaranteed" as per MSDN:
// should not be used to iterate over an Array where index order is important. Array indexes are just enumerable properties with integer names and are otherwise identical to general Object properties. There is no guarantee that will return the indexes in any particular order and it will return all enumerable properties, including those with non–integer names and those that are inherited.
for (var c in enumerate(myArr)){
// Ideally add to a UTILS object or something.
var enumerate = function(arr){
var len = arr.length,
keys = Object.keys(arr),
result = {};
result[keys[len]] = a[len];
return result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.