Tech Junkie Blog - Real World Tutorials, Happy Coding!: JavaScript Array Methods: The Array.join() Method

Monday, December 6, 2021

JavaScript Array Methods: The Array.join() Method

The Array.join() method converts all of the elements of an array into strings and concatenates the elements.  If no delimiter is defined it is separated by a comma.  The most common use for this is to convert an array into a comma separated list of strings.

For example let's say we want to convert an array of zip codes into a comma separated list.

    <script>
        var zipCodes = [90210, 90211, 90212, 90213, 90214];
    </script>

If we just call the zipCodes.join() method we will get a string of comma separated list












If we want to separate the zip codes with a dash we can specify the separator like the following zipCodes.join("-")








Well you get the idea, if you want to separate your elements with a space you would type zipCodes.join(" ")









2 comments:

  1. Dealing with complex technical drawings and 3D modelling can be genuinely overwhelming for students. That's exactly why having access to reliable and affordable AutoCAD assignment help UK services makes such a huge difference. From precise measurements to layer organisation and mechanical drawings, expert guidance simplifies everything. What truly stands out is the 24/7 support, free revisions, and personalised assistance tailored to every student's needs. Whether you're a beginner or working on advanced projects, professional support helps you submit accurate, high-quality work on time and achieve the academic results you've always aimed for!

    ReplyDelete