Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to rename keys in objects #1196

Closed
nisanthchunduru opened this issue Jul 9, 2013 · 1 comment
Closed

Add function to rename keys in objects #1196

nisanthchunduru opened this issue Jul 9, 2013 · 1 comment

Comments

@nisanthchunduru
Copy link

Add function to rename keys in an object

> var _ = require('underscore');
> var note = {
... '_id': 1,
... 'title': 'Ruby is awesome..',
... 'text': '..and so is CoffeeScript'
... }
> console.log(_.rename(note, [['_id', 'id']]));
{ id: 1,
  title: 'Ruby is awesome..',
  text: '..and so is CoffeeScript' }

or an array of objects

> var notes = [note, note];
> console.log(_.rename(notes, [['_id', 'id']]));
[ { id: 1,
    title: 'Ruby is awesome..',
    text: '..and so is CoffeeScript' },
  { id: 1,
    title: 'Ruby is awesome..',
    text: '..and so is CoffeeScript' } ]

Thanks,
Nisanth

@jashkenas
Copy link
Owner

Thanks, but no thanks -- way too special case for core Underscore. Feel free to mix it in for your own purposes.

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

No branches or pull requests

2 participants