Underscore: Tambahkan fungsi untuk mengganti nama kunci di objek

Dibuat pada 9 Jul 2013  ·  1Komentar  ·  Sumber: jashkenas/underscore

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

enhancement wontfix

>Semua komentar

Terima kasih, tapi tidak, terima kasih -- kasus yang terlalu istimewa untuk Inti Garis Bawah. Jangan ragu untuk mencampurnya untuk tujuan Anda sendiri.

Apakah halaman ini membantu?
0 / 5 - 0 peringkat

Masalah terkait

markvr picture markvr  ·  3Komentar

danilopolani picture danilopolani  ·  5Komentar

sky0014 picture sky0014  ·  8Komentar

afranioce picture afranioce  ·  8Komentar

arieljake picture arieljake  ·  4Komentar