# Joining lists with new lines

**URL:** <https://forum.code.org/t/joining-lists-with-new-lines/38976>\
**Category:** Unit and Lesson Discussion\
**Created:** [February 1, 2024, 7:16pm UTC](https://forum.code.org/t/joining-lists-with-new-lines/38976 "2024-02-01T19:16:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![heather\_l\_minneman](https://avatars.discourse-cdn.com/v4/letter/h/aeb1de/32.png) [@heather\_l\_minneman](https://forum.code.org/u/heather_l_minneman)\
**Post date:** [February 1, 2024, 7:16pm UTC](https://forum.code.org/t/joining-lists-with-new-lines/38976/1 "2024-02-01T19:16:32Z")

</div>

I am trying to write code to have 2 parallel lists show up on the same line so that they scroll together in a text area.

So if my ListA=[‘apple’,‘banana’,‘corn’] and ListB=[1.25,0.59,0.75], I want them to be displayed as  
apple 1.25  
banana 0.59  
corn 0.75

I feel like I have seen this previously, but I can’t find the code.

Thanks.  
-Heather

---

<div class="post-metadata">

**Author:** ![bhatnagars](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/bhatnagars/32/4919_2.png) [@bhatnagars](https://forum.code.org/u/bhatnagars)\
**Post date:** [February 1, 2024, 8:46pm UTC](https://forum.code.org/t/joining-lists-with-new-lines/38976/2 "2024-02-01T20:46:42Z")

</div>

Unit 6 lesson 11 level 1 is doing something similar. If you looking for documentation on the join function to convert a list to a string, you can find it [here](https://studio.code.org/docs/ide/applab/expressions/join).

---

<div class="post-metadata">

**Author:** ![varrience](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/varrience/32/8042_2.png) [@varrience](https://forum.code.org/u/varrience)\
**Post date:** [February 2, 2024, 11:38am UTC](https://forum.code.org/t/joining-lists-with-new-lines/38976/3 "2024-02-02T11:38:01Z")

</div>

hmm from my understanding you just want to concatenate separate arrays, in this case i would refrain from using .join() more rather using an iterator to combine two lists together; more rather have a new array in which both are combined into where you can call .split() to produce the proper output

> Here’s My Example

```auto
var a = ["apple", "banana", "corn"];
var b = [1.25, 0.59, 0.75];
/**
 * @description Combines two arrays together in string format
 * @param {Array} arr1 prefix
 * @param {Array} arr2 surrogate
 * @returns {Array}
 */
function fuseList(arr1, arr2) {
    var arr = [];
    for (var i = 0; i < Math.max(arr1.length, arr2.length); i++) {
        if (arr1[i] == undefined) { arr1[i] = "N/A" }
        if (arr2[i] == undefined) { arr2[i] = "N/A" }
        arr.push(arr1[i] + " " + arr2[i]);
    }
    return (arr);
}
console.log(fuseList(a, b).split("\n"))

```
