For a basic example of the join methods I put together some examples that involve an array of folder names that need to be combined together into an string that can be used as a corresponding path with a ‘\/‘ separator. Maybe not the best use case example, especially if you are working in a nodejs environment as the path.join method should be used there for something like this, but still it should server the purpose of a simple example.
To use the lodash method I just need to call _.join, pass the array, and then give the separator that I want between elements when making the string. This will give me a string that will work okay as a path in some cases. If I all ready have a string that is formated in a way in which there is a ‘\/‘ separator between folder names I can use the _.split method to split that string into an array of elements, reversing the process.
The native Array.join method works in very much the same manor only it is a prototype method of Array, so I call it as such, and only give the separator.
Just as with the lodash split method there is also the native string split method.
When I split a string into an array, in some cases I will end up with additional empty elements. This then gives rise for a need to have a way to filter out these typically unwanted extra elements. One way to go about doing this would be to make use of the array filter method.