Skip to content

Commit 52ae0cd

Browse files
committed
extend arrays#join docs
1 parent 18d81c1 commit 52ae0cd

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

packages/arrays.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ items.isNotEmpty()
478478
479479
#### join
480480
- *added in `1.0`*
481+
- *updated in `4.2`*
481482
482483
The `join` method returns a string of all items concatenated. By default, it uses a comma `,` for concatenation:
483484
@@ -493,10 +494,30 @@ You can provide a separator that will then be used for concatenation:
493494
```js
494495
const names = Arr.from([1, 2, 3])
495496
496-
names.join()
497+
names.join('; ')
497498
// '1; 2; 3'
498499
```
499500
501+
Since version `4.2` you can provide a second argument defining how to append the last item:
502+
503+
```js
504+
const names = Arr.from([1, 2, 3])
505+
506+
names.join(', ', ', and')
507+
// '1, 2, and 3'
508+
```
509+
510+
Since version `4.2` you may also provide a callback function that returns the value that will be joined into the resulting string value:
511+
512+
```js
513+
const names = Arr.from([1, 2, 3])
514+
515+
names.join((value, index, arr) => {
516+
return `${value} --> `
517+
})
518+
// '1 --> 2 --> 3 --> '
519+
```
520+
500521
501522
#### last
502523
- *added in version `1.1`*

0 commit comments

Comments
 (0)