javascript - Is there a way to get the iteration number with angular foreach on an object -


is there way can iteration number inside angular foreach (when iterating through object : {'foo': 'blah', 'blah': 'foo'} ? iterator function in case, value 'blah' , 'foo' while key 'foo' , 'blah'

angulars foreach when iterating object doesn't tell how many times iterated objects keys.

when iterating array doesn't tell how many times ran current position in array. it's me being pedantic there difference.

however alternative give current position in objects keys use native object.keys(). return array of objects keys, can iterate on them normal array , current position in array.

var obj = {'foo': 'blah', 'blah': 'foo'};  object.keys(obj)     .foreach(function (key, index) {         console.log('key', key, 'value', obj[key]);         console.log('ive ran ', index);     }); 

docs: https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/object/keys


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -