Listify a JavaScript ArrayFebruary 18th, 2021 — 6 min read When you want to display a list of items to a user, I'm afraid .join(', ') just won't cut it: console.log(['apple'].join(', ')) // apple // looks good console.log(['apple', 'grape'].join(', ')) // apple, grape // nah, I want "apple and grape" console.log(['apple', 'grape', 'pear'].join(', ')) // apple, grape, pear // wut? Ok, so bust out y
![Listify a JavaScript Array](https://cdn-ak-scissors.b.st-hatena.com/image/square/5e9cd2e38393bfa153e9bba4efc994919e7f69bb/height=288;version=1;width=512/https%3A%2F%2Fres.cloudinary.com%2Fkentcdodds-com%2Fimage%2Fupload%2F%24th_1256%2C%24tw_2400%2C%24gw_%24tw_div_24%2C%24gh_%24th_div_12%2Fco_rgb%3Aa9adc1%2Cc_fit%2Cg_north_west%2Cw_%24gw_mul_14%2Ch_%24gh%2Cx_%24gw_mul_1.5%2Cy_%24gh_mul_1.3%2Cl_text%3Akentcdodds.com%3AMatter-Regular.woff2_50%3ACheck%252520out%252520this%252520article%2Fco_white%2Cc_fit%2Cg_north_west%2Cw_%24gw_mul_13.5%2Ch_%24gh_mul_7%2Cx_%24gw_mul_1.5%2Cy_%24gh_mul_2.3%2Cl_text%3Akentcdodds.com%3AMatter-Regular.woff2_110%3AListify%252520a%252520JavaScript%252520Array%2Fc_fit%2Cg_north_west%2Cr_max%2Cw_%24gw_mul_4%2Ch_%24gh_mul_3%2Cx_%24gw%2Cy_%24gh_mul_8%2Cl_kent%3Aprofile-transparent%2Fco_rgb%3Aa9adc1%2Cc_fit%2Cg_north_west%2Cw_%24gw_mul_5.5%2Ch_%24gh_mul_4%2Cx_%24gw_mul_4.5%2Cy_%24gh_mul_9%2Cl_text%3Akentcdodds.com%3AMatter-Regular.woff2_70%3AKent%2520C.%2520Dodds%2Fco_rgb%3Aa9adc1%2Cc_fit%2Cg_north_west%2Cw_%24gw_mul_9%2Cx_%24gw_mul_4.5%2Cy_%24gh_mul_9.8%2Cl_text%3Akentcdodds.com%3AMatter-Regular.woff2_40%3Akentcdodds.com%25252Fblog%25252Flistify-a-java-script-array%2Fc_fill%2Car_3%3A4%2Cr_12%2Cg_east%2Ch_%24gh_mul_10%2Cx_%24gw%2Cl_unsplash%3Aphoto-1507925921958-8a62f3d1a50d%2Fc_fill%2Cw_%24tw%2Ch_%24th%2Fkentcdodds.com%2Fsocial-background.png)