String array to integer array

array=[“1”,“3”,“4”]
How do i convert this array to
sessionarraydb_array=[1,3,4,]

array.map(&:to_i)

Walter

try-
array=[“1”,“3”,“4”]

On Wed, Jul 18, 2012 at 8:25 PM, deal bitte [email protected]
wrote:

To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit https://groups.google.com/groups/opt_out.


Regards,
Himanshu P.
(+91) 959 559 1648

ignore last reply and try this-
array.map!{|e| e.to_i}

On Wed, Jul 18, 2012 at 8:30 PM, Himanshu P.
[email protected]wrote:


Regards,
Himanshu P.
(+91) 959 559 1648


Regards,
Himanshu P.
(+91) 959 559 1648

Here is another way to do that…

array = [“1”,“3”,“4”]
array.collect do |n|
n.to_i
end

It will return you a new integer array
[1, 3, 4]

If you want to change your array in place then just put an exclamation
mark
after the method collect like this…

array.collect! do |n|

No need to do this…

array.map!{|e| e.to_i}

you can do this with the first code also with a change…

array.map!(&:to_i)