DEV Community

One line of code (JS) Series' Articles

Back to Martin Krause's Series
1 line of code: How to count all occurrences in an Array
Cover image for 1 line of code: How to count all occurrences in an Array

1 line of code: How to count all occurrences in an Array

56
Comments 2
1 min read
1 line of code: How to shallow clone an Array
Cover image for 1 line of code: How to shallow clone an Array

1 line of code: How to shallow clone an Array

30
Comments 7
1 min read
1 line of code: How to check if an Array is empty
Cover image for 1 line of code: How to check if an Array is empty

1 line of code: How to check if an Array is empty

41
Comments 18
1 min read
1 line of code: How to remove all duplicates from an Array
Cover image for 1 line of code: How to remove all duplicates from an Array

1 line of code: How to remove all duplicates from an Array

45
Comments 11
1 min read
1 line of code: How to get lowest numeric element of an Array
Cover image for 1 line of code: How to get lowest numeric element of an Array

1 line of code: How to get lowest numeric element of an Array

19
Comments
1 min read
1 line of code: How to get highest numeric item of an Array
Cover image for 1 line of code: How to get highest numeric item of an Array

1 line of code: How to get highest numeric item of an Array

30
Comments 9
1 min read
1 line of code: How to get the closest numeric item of an Array
Cover image for 1 line of code: How to get the closest numeric item of an Array

1 line of code: How to get the closest numeric item of an Array

7
Comments 3
1 min read
1 line of code: How to get the index of the lowest numeric item of an Array
Cover image for 1 line of code: How to get the index of the lowest numeric item of an Array

1 line of code: How to get the index of the lowest numeric item of an Array

5
Comments 2
1 min read
1 line of code: How to get the first index of the highest numeric item of an Array
Cover image for 1 line of code: How to get the first index of the highest numeric item of an Array

1 line of code: How to get the first index of the highest numeric item of an Array

5
Comments
1 min read
1 line of code: How to split an Array in half
Cover image for 1 line of code: How to split an Array in half

1 line of code: How to split an Array in half

23
Comments 17
1 min read
1 line of code: How to get the longest string of an Array
Cover image for 1 line of code: How to get the longest string of an Array

1 line of code: How to get the longest string of an Array

5
Comments
1 min read
1 line of code: How to get the shortest string of an Array
Cover image for 1 line of code: How to get the shortest string of an Array

1 line of code: How to get the shortest string of an Array

4
Comments
1 min read
1 line of code: How to the get length of the shortest string of an Array
Cover image for 1 line of code: How to the get length of the shortest string of an Array

1 line of code: How to the get length of the shortest string of an Array

6
Comments 2
1 min read
1 line of code: How to get the length of the longest string of an Array
Cover image for 1 line of code: How to get the length of the longest string of an Array

1 line of code: How to get the length of the longest string of an Array

6
Comments
1 min read
1 line of code: How to get every odd item of an Array
Cover image for 1 line of code: How to get every odd item of an Array

1 line of code: How to get every odd item of an Array

25
Comments 13
1 min read
1 line of code: How to get every even item of an Array
Cover image for 1 line of code: How to get every even item of an Array

1 line of code: How to get every even item of an Array

19
Comments 16
1 min read
1 line of code: How to merge two Arrays and clean all duplicate entries
Cover image for 1 line of code: How to merge two Arrays and clean all duplicate entries

1 line of code: How to merge two Arrays and clean all duplicate entries

33
Comments 3
1 min read
1 line of code: How to merge two Arrays and preserve all entries
Cover image for 1 line of code: How to merge two Arrays and preserve all entries

1 line of code: How to merge two Arrays and preserve all entries

3
Comments
1 min read
1 line of code: How to clean an Array
Cover image for 1 line of code: How to clean an Array

1 line of code: How to clean an Array

48
Comments 13
1 min read
1 line of code: How to clean an Array of "falsy" items
Cover image for 1 line of code: How to clean an Array of "falsy" items

1 line of code: How to clean an Array of "falsy" items

5
Comments 2
1 min read
1 line of code: How to get the sum of an array of numbers
Cover image for 1 line of code: How to get the sum of an array of numbers

1 line of code: How to get the sum of an array of numbers

3
Comments 2
1 min read
1 line of code: How to get the average of an array
Cover image for 1 line of code: How to get the average of an array

1 line of code: How to get the average of an array

10
Comments 9
1 min read
1 line of code: How to get every n-th item of an Array
Cover image for 1 line of code: How to get every n-th item of an Array

1 line of code: How to get every n-th item of an Array

4
Comments 2
1 min read
1 line of code: How to sort an array by ascending order
Cover image for 1 line of code: How to sort an array by ascending order

1 line of code: How to sort an array by ascending order

3
Comments
1 min read
1 line of code: How to sort an array by descending order
Cover image for 1 line of code: How to sort an array by descending order

1 line of code: How to sort an array by descending order

13
Comments 2
1 min read
1 line of code: How to shuffle an array
Cover image for 1 line of code: How to shuffle an array

1 line of code: How to shuffle an array

3
Comments
1 min read
1 line of code: How to create a range array
Cover image for 1 line of code: How to create a range array

1 line of code: How to create a range array

5
Comments 10
1 min read
1 line of code: How to count the words in a string
Cover image for 1 line of code: How to count the words in a string

1 line of code: How to count the words in a string

5
Comments 5
1 min read
1 line of code: How to capitalise a string
Cover image for 1 line of code: How to capitalise a string

1 line of code: How to capitalise a string

6
Comments 2
1 min read
1 line of code: How to camelCase a string
Cover image for 1 line of code: How to camelCase a string

1 line of code: How to camelCase a string

24
Comments 6
1 min read
1 line of code: How to PascalCase a string
Cover image for 1 line of code: How to PascalCase a string

1 line of code: How to PascalCase a string

5
Comments
1 min read
1 line of code: How to create an URL Slug from a string
Cover image for 1 line of code: How to create an URL Slug from a string

1 line of code: How to create an URL Slug from a string

7
Comments 4
1 min read
1 line of code: How to convert html special chars
Cover image for 1 line of code: How to convert html special chars

1 line of code: How to convert html special chars

5
Comments
1 min read
1 line of code: How to lower case a string
Cover image for 1 line of code: How to lower case a string

1 line of code: How to lower case a string

6
Comments 1
1 min read
1 line of code: How to convert tabs to spaces
Cover image for 1 line of code: How to convert tabs to spaces

1 line of code: How to convert tabs to spaces

19
Comments 9
1 min read
1 line of code: How to convert spaces to tabs
Cover image for 1 line of code: How to convert spaces to tabs

1 line of code: How to convert spaces to tabs

17
Comments 3
1 min read
1 line of code: How to convert \newlines to <breaks />
Cover image for 1 line of code: How to convert \newlines to <breaks />

1 line of code: How to convert \newlines to <breaks />

7
Comments 5
1 min read
1 line of code: How to replace multiple spaces with one space
Cover image for 1 line of code: How to replace multiple spaces with one space

1 line of code: How to replace multiple spaces with one space

18
Comments 1
1 min read
1 line of code: How to reverse all words of a string
Cover image for 1 line of code: How to reverse all words of a string

1 line of code: How to reverse all words of a string

28
Comments 6
1 min read
1 line of code: How to reverse a string
Cover image for 1 line of code: How to reverse a string

1 line of code: How to reverse a string

31
Comments 10
1 min read
1 line of code: How to truncate a string at word boundaries
Cover image for 1 line of code: How to truncate a string at word boundaries

1 line of code: How to truncate a string at word boundaries

10
Comments 3
1 min read