新手问题 如何去除一个数组中的子元素中的双引号

LPFpengfei · November 16, 2017 · Last by LPFpengfei replied at November 16, 2017 · 3291 hits

如题: 一个数组为

a = ["1","2","3","4"]

如何让这个数组变成

b = [1,2,3,4]

急,在线等。。。。。新手求大神解释!!!!

a.map(&:to_i)

Reply to yingce

谢谢,有文档之类的说明吗,这是为什么,我试了很多办法都不行。。。。。

Reply to LPFpengfei

这个等价于 a.map { |a| a.to_i } 遍历数组每个值 to_i

Reply to yingce

哦哦哦,这么看我就懂了,万分感谢!!!

LPFpengfei closed this topic. 16 Nov 22:56
You need to Sign in before reply, if you don't have an account, please Sign up first.