0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ハッシュからキーを取り出して配列に格納する

Posted at

問題

book = {title: "多動力", price: 1280, impression: モチベが上がる}

上記のようなハッシュからキーだけを取り出して配列に格納するにはどうしたら良いでしょうか

方法

ハッシュに対してkeysメソッドを使用して配列に格納します。

array = book.keys

出力すると

puts array

キーだけが取り出されて出力されます

ターミナル
title
price
impression

この方法でハッシュからキーだけを取り出して配列に格納することができます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?