Skip to content

Instantly share code, notes, and snippets.

@iandanforth
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save iandanforth/bb87bc11ce9bdc704527 to your computer and use it in GitHub Desktop.

Select an option

Save iandanforth/bb87bc11ce9bdc704527 to your computer and use it in GitHub Desktop.
Sublime Snippet: JavaScript functional equivalent of Python's dict.iteritems() or dict.items()
<snippet>
<content><![CDATA[for (var ${20:key} in ${1:Thing}) {
if (${1:Thing}.hasOwnProperty(${20:key})) {
var ${300:val} = ${1:Thing}[${20:key}];
${4000}
}
};]]></content>
<tabTrigger>for</tabTrigger>
<scope>source.js</scope>
<description>for key, val in object</description>
</snippet>
@iandanforth
Copy link
Author

Installation:

Save to <path/to>/Packages/User dir
Should be available immediately within .js files.

Use:

  • for (select from dropdown list)
  • type name of object,
  • type name of key variable [Default: "key"]
  • type name of value variable [Default: "val"]
  • write your code.

Default example:

for (var key in Thing) {
    if (Thing.hasOwnProperty(key)) {
        var val = Thing[key];

    }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment