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

Reactions 57 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

Reactions 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

Reactions 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

Reactions 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

Reactions 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

Reactions 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

Reactions 8 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

Reactions 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

Reactions 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

Reactions 18 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

Reactions 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

Reactions 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

Reactions 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

Reactions 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

Reactions 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

Reactions 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

Reactions 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

Reactions 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

Reactions 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

Reactions 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

Reactions 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

Reactions 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

Reactions 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

Reactions 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

Reactions 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

Reactions 4 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

Reactions 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

Reactions 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

Reactions 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

Reactions 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

Reactions 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

Reactions 6 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

Reactions 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

Reactions 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

Reactions 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

Reactions 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 />

Reactions 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

Reactions 21 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

Reactions 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

Reactions 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

Reactions 10 Comments 2
1 min read