คลายแฟ้มค่าจากรูบี้อาเรย์

รหัสตัวอย่าง

0
0

รูบี้คลายแฟ้มส่วนประกอบจากตารางคู่ลำดับ

Suppose you have an array of hashes like this:

```ruby
arr = [{a: 1, b: 2}, {c: 3, d: 4}, {e: 5, f: 6}]
```

You can extract the values corresponding to a given key like this:

```ruby
arr.map { |h| h[:a] }
# => [1, nil, nil]
```

```ruby
arr.map { |h| h[:b] }
# => [2, nil, nil]
```

```ruby
arr.map { |h| h[:c] }
# => [nil, 3, nil]
```

```ruby
arr.map { |h| h[:d] }
# => [nil, 4, nil]
```

```ruby
arr.map { |h| h[:e] }
# => [nil, nil, 5]
```

```ruby
arr.map { |h| h[:f] }
# => [nil, nil, 6]
```

If you want to get all the values for all the keys, you can use `#values`:

```ruby
arr.map { |h| h.values }
# => [[1, 2], [3, 4], [5, 6]]
```

หน้าคล้ายกัน

คล้ายกันหน้ากับตัวอย่าง

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................