Tambahkan fungsi untuk mengganti nama kunci dalam suatu objek
> 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' }
atau serangkaian objek
> 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' } ]
Terima kasih,
Nisanth
Terima kasih, tapi tidak, terima kasih -- kasus yang terlalu istimewa untuk Inti Garis Bawah. Jangan ragu untuk mencampurnya untuk tujuan Anda sendiri.