• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Miscellaneous / Combine all items in an array into a string

Combine all items in an array into a string

Combine all items in an array into a string

Combine all items in an array into a string, separated by a delimiter that you can pass in as an argument. By default, it will use a comma (,) as the delimiter if one is not provided.

var strings = [
	'I love Cape Cod potato chips.',
	'What about you?'
];

var concat = strings.join();
var concatWithSpace = strings.join(' ');
var concatWithSmiley = strings.join(' =) ');

// logs "I love Cape Cod potato chips.,What about you?"
console.log(concat);

// logs "I love Cape Cod potato chips. What about you?"
console.log(concatWithSpace);

// logs "I love Cape Cod potato chips. =) What about you?"
console.log(concatWithSmiley);

Source

https://vanillajstoolkit.com/reference/arrays/array-join/

Miscellaneous

Related Snippets:

  • Tell the browser when to run your JavaScript code
  • Insert an element into the DOM after another one
  • Create a one time event handler
  • Create a new array from an existing one

Primary Sidebar

FREE UPDATES!

Get the latest updates in your inbox for FREE!

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2023 JavaScriptSource.com

  • About
  • Privacy Policy
  • Submit
  • FAQ
  • Jobs For Developers
  • Contact Us