Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个数组,
array = [1,2,3]
需要将其转换为:
newArray = [{id: 1}, {id: 2}, {id: 3}]
我知道这一点,有什么有效的方法吗?
array.each { |id| newArray << { id: id } }
有这样的吗?
array.map { |id| Hash[:id, id] }
与哈希文字相同
array.map { |id| { id: id } }