This repository contains custom extensions for JavaScript’s Array and String prototypes, providing additional utility functions.
String Prototype Extension
capitalizeFirstLetter: Capitalizes the first letter of a string.
Array Prototype Extensions
groupBy(callback): Groups array elements based on the provided callback.
groupByKey(keyName): Groups array of objects by a specific key.
distinct(): Returns an array with distinct elements.
distinctByKey(key): Returns an array of unique objects based on a specific key.
sortBy(callback): Sorts the array based on a custom callback function.
sortByKey(key): Sorts the array of objects based on a specific key.
sum(callback): Computes the sum of an array based on a callback function.
sumByKey(key): Computes the sum of an array of objects based on a specific key.
chunk(size): Splits the array into chunks of a specified size.
unique(): Returns an array with unique elements.
uniqueBy(key): Returns an array of unique objects based on a specific key.
remove(item): Removes a specific item from the array.
removeByKeyValue(key, value): Removes items based on a specific key-value pair.
findIndexByKeyValue(key, value): Finds the index of an object based on a specific key-value pair.
findKeyValue(key, value): Finds an object based on a specific key-value pair.
findValueByKeyValue(key, value, retrieveKey): Finds the value of a specific key in an object based on another key-value pair.
Get Abhishek Vishwakarma’s stories in your inbox
Join Medium for free to get updates from this writer.
Usage
Import the JavaScript extension script before using any of the provided functions. This script adds custom functionality to the String and Array prototypes.