You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-9
Original file line number
Diff line number
Diff line change
@@ -50,20 +50,31 @@ Using `@supercharge/arrays` is pretty straightforward. The package exports a fun
50
50
```js
51
51
const { Arr } =require('@supercharge/arrays')
52
52
53
-
consthasItemsGreaterTen=Arr([1, 2, 3, 4, 5, 6])
54
-
.map(value=> value *2) // [2, 4, 6, 8, 10, 12]
55
-
.filter(value=> value >10) // [12]
56
-
.isNotEmpty() // true
53
+
constusers=Arr.from([])
57
54
55
+
users.isEmpty()
56
+
// true
58
57
59
-
// Only methods, no properties
60
-
Arr([1, 2, 3]).length() // 3
58
+
users
59
+
.push({ id:1, name:'Marcus' })
60
+
.push({ id:2, name:'Norman' })
61
+
.push({ id:3, name:'Christian' })
61
62
63
+
users.isNotEmpty()
64
+
// true
62
65
63
-
// Supports callbacks for `.includes`:
64
-
Arr([1, 2, 3]).includes(value=> {
65
-
return value >2
66
+
users.length()
67
+
// 3
68
+
69
+
constusernamesArray= users
70
+
.map(user=>user.name)
71
+
.toArray()
72
+
// [ 'Marcus', 'Norman', 'Christian' ]
73
+
74
+
constmarcus=users.find(user=> {
75
+
returnuser.name==='Marcus'
66
76
})
77
+
// { id: 1, name: 'Marcus' }
67
78
```
68
79
69
80
Every method in the chain returns a `@supercharge/array` instance. This way, you can chain further methods without leaving the fluent interface. Call `.all()` to retrieve the plain JavaScript array.
0 commit comments