Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 411627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:00:19+00:00 2026-05-12T18:00:19+00:00

i have 4 arrays. [one, two, three] [1, 2, 3 [un, deux, trois] [ichi,

  • 0

i have 4 arrays.

["one", "two", "three"]
["1", "2", "3"
["un", "deux", "trois"]
["ichi", "ni", "san"]

is it possible to concatenate each element in their respective arrays ?

so i end up with single lines of string like like

"one, 1, un, ichi"\n
"two,2, deux,ni"\n

and so on…

is it possible to do this in one loop ?

for i in (1..array1.count)

puts array1[i] + ", " + array2[i] + ", " + array3[i] + ", " + array4[i]

end

What happens when there might be unpredictable number of arrays & they are each unequal size?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:00:20+00:00Added an answer on May 12, 2026 at 6:00 pm

    Well if you know that they were all the same length:

    (0...array1.length).each{|i|puts array1[i] + ", " + array2[i] + ", " + array3[i] + ", " + array4[i]}
    

    Edit: The Following code works

    array1 = ["one", "two", "three"]
    array2 = ["1", "2", "3"]
    array3 = ["un", "deux", "trois"]
    array4 = ["ichi", "ni", "san"]
    
    (0...array1.length).each{|i| puts array1[i] + ", " + array2[i] + ", " + array3[i] + ", " + array4[i]}
    

    Edit2: what happens if you dont know how many arrays there will be?

    I would suggest making an array of arrays; a list of arrays. Make an array of arrays (essentially a 2D array but it can’t be indexed like one) and with it print every line one by one for each array in the arrayList.

    This code works:

    array1 = ["one", "two", "three"]
    array2 = ["1", "2", "3"]
    array3 = ["un", "deux", "trois"]
    array4 = ["ichi", "ni", "san"]
    
    arrayList = []
    arrayList.push(array1, array2, array3, array4)
    
    p arrayList
    
    (0...array1.length).each{|i|
        (0...arrayList.length).each{|j|
            print arrayList[j][i] + ", "
        }
        print "\n"
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two String arrays a,b. String a [] = {one,two,three}; String b []
I have 3 String arrays with constants. eg: String[] digit = {one, two, three};
lets say I have 2 arrays my @one = (one,two,three,four,five); my @two = (three,five);
So I have a couple of arrays $array_1 = Array('one','two','three'); $array_2 = Array('red','blue','green'); Is
Lets say I have random $variable and three arrays: $array1 = (one, two, three);
What's the best and way to do this: I have two arrays: a=[['a','one'],['b','two'],['c','three'],['d','four']] and
I have two arrays var nodes = new Array(alpha,beta,omega); var childnodes = new Array(one,two,three);
Lets say I have 2 arrays . $arr1=array(foo=>bar, 1=>one, 2=>two); $arr2=array(h=>eich, 3=>three, 4=>four); By
Say I have two arrays where one is a permutation of the other: A
I have two arrays and I post the arrays in one input; <input name='sistem[]'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.