A comprehensive collection of JavaScript programming methods with detailed explanations, practical examples, and best practices.
javascript-programming-methods/
βββ array-methods/
β βββ filter.js - Filter array elements by condition
β βββ find.js - Find elements (find, findIndex, findLast)
β βββ flat-flatMap.js - Flatten nested arrays
β βββ forEach.js - Iterate over array elements
β βββ includes-indexOf.js - Search methods (includes, indexOf, lastIndexOf)
β βββ map.js - Transform array elements
β βββ reduce.js - Reduce array to single value
β βββ slice-splice.js - Extract and modify arrays
β βββ some-every.js - Test array conditions
β βββ sort.js - Sort array elements
βββ string-methods/
β βββ string-methods.js - Comprehensive string operations
βββ object-methods/
β βββ object-methods.js - Object manipulation and utilities
βββ function-methods/
β βββ function-methods.js - Function utilities and patterns
βββ promise-methods/
β βββ promise-methods.js - Asynchronous programming
βββ utility-methods/
β βββ utility-methods.js - General utility functions
βββ index.js - Main entry point
Each method implementation includes:
- β Detailed explanation of how the method works
- β Syntax and parameters with type information
- β Return values clearly documented
- β Practical examples with real-world scenarios
- β Use cases demonstrating when to use each method
- β Best practices and common pitfalls to avoid
- β Custom implementations to understand internals
- β Performance considerations and time/space complexity
- β Edge cases and special behaviors
- β Comparison with similar methods
map()- Transform each element and create new arrayfilter()- Create new array with elements that pass a testreduce()- Reduce array to a single valueflat()- Flatten nested arrays to specified depthflatMap()- Map and flatten in one operation
find()- Find first element matching conditionfindIndex()- Find index of first matching elementfindLast()- Find last matching element (ES2023)findLastIndex()- Find index of last matching element (ES2023)includes()- Check if array contains a valueindexOf()- Find first index of a valuelastIndexOf()- Find last index of a value
forEach()- Execute function for each elementsome()- Test if at least one element passesevery()- Test if all elements pass
sort()- Sort array elements in placeslice()- Extract portion without modifying originalsplice()- Add/remove elements (mutates array)
charAt()- Get character at specific indexcharCodeAt()- Get Unicode value at indexindexOf()- Find first occurrence of substringlastIndexOf()- Find last occurrence of substringincludes()- Check if string contains substringstartsWith()- Check if string starts with substringendsWith()- Check if string ends with substring
slice()- Extract part of stringsubstring()- Extract substringsubstr()- Extract substring by length (deprecated)
toLowerCase()- Convert to lowercasetoUpperCase()- Convert to uppercasetrim()- Remove whitespace from both endstrimStart()/trimEnd()- Remove whitespace from one endpadStart()/padEnd()- Pad string to lengthrepeat()- Repeat string n times
replace()- Replace first occurrencereplaceAll()- Replace all occurrences (ES2021)split()- Split string into arrayconcat()- Concatenate strings
match()- Match against regexmatchAll()- Get all regex matches (ES2020)search()- Search for regex pattern
Object.create()- Create object with specified prototypeObject.assign()- Copy properties between objects (shallow)
Object.keys()- Get enumerable property namesObject.values()- Get enumerable property valuesObject.entries()- Get [key, value] pairsObject.fromEntries()- Create object from entriesObject.getOwnPropertyNames()- Get all property namesObject.getOwnPropertyDescriptor()- Get property descriptor
Object.defineProperty()- Define single property with descriptorObject.defineProperties()- Define multiple properties
Object.freeze()- Make object immutableObject.seal()- Prevent property addition/removalObject.preventExtensions()- Prevent new properties
Object.getPrototypeOf()- Get object's prototypeObject.setPrototypeOf()- Set object's prototypehasOwnProperty()- Check for own property
Object.is()- Same-value equality comparisonObject.isFrozen()/isSealed()/isExtensible()- Check object state
call()- Invoke function with specific contextapply()- Invoke function with arguments arraybind()- Create bound function with fixed context
- Functions as arguments
- Functions returning functions
- Function composition
- Function piping
- Closures - Data privacy and encapsulation
- Currying - Partial application of arguments
- Memoization - Caching function results
- Debouncing - Delay execution until idle
- Throttling - Limit execution frequency
- Decorators - Enhance function behavior
Promise.resolve()- Create resolved promisePromise.reject()- Create rejected promisenew Promise()- Create custom promise
Promise.all()- Wait for all to resolve (fails fast)Promise.allSettled()- Wait for all to settle (ES2020)Promise.race()- Wait for first to settlePromise.any()- Wait for first to resolve (ES2021)
asyncfunctions - Cleaner async syntaxawaitoperator - Wait for promise resolution- Error handling with try/catch
- Parallel vs sequential execution
- Retry logic
- Timeout patterns
- Circuit breaker
- Promise queues
- Batch processing
- Type validators (isString, isNumber, isObject, etc.)
- Array type checking
- Null/undefined handling
- Deep clone - Recursive object copying
- Deep equal - Recursive object comparison
- Deep merge - Merge nested objects
- Object validation
- unique() - Remove duplicates
- flatten() - Flatten nested arrays
- chunk() - Split into chunks
- shuffle() - Random shuffle
- groupBy() - Group by property
- partition() - Split by predicate
- Case conversion - camelCase, kebab-case, snake_case
- Truncate - Limit string length
- Template - String interpolation
- Slug generation - URL-friendly strings
- HTML escape/strip - Security helpers
- Random - Random number generation
- Clamp - Constrain to range
- Round - Precision rounding
- Format - Currency, number formatting
- Statistics - Average, median, std deviation
- Format - Date formatting
- Add/subtract - Date arithmetic
- Comparison - Date differences
- Relative time - "2 hours ago" formatting
- Email validation
- Phone validation
- URL validation
- Credit card validation
- Password strength
- Custom validators
- Node.js (v12 or higher) or a modern web browser
- Basic understanding of JavaScript
-
Clone this repository
git clone https://github.com/yourusername/javascript-programming-methods.git cd javascript-programming-methods -
Explore method categories
# Browse available methods ls array-methods/ ls string-methods/ ls object-methods/ -
Run examples
# Run any method file node array-methods/map.js node string-methods/string-methods.js node promise-methods/promise-methods.js
Each file contains comprehensive examples and can be run independently:
# Array methods
node array-methods/filter.js
node array-methods/reduce.js
node array-methods/sort.js
# String methods
node string-methods/string-methods.js
# Promise methods
node promise-methods/promise-methods.jsYou can also import and use these methods as reference:
// Study the implementations and patterns
// Then apply them in your own code
// Example: Custom filter implementation
Array.prototype.customFilter = function(callback) {
const result = [];
for (let i = 0; i < this.length; i++) {
if (callback(this[i], i, this)) {
result.push(this[i]);
}
}
return result;
};- Start with Array Methods:
map(),filter(),forEach() - Learn String Methods:
split(),join(),slice() - Understand Basic Object Methods:
Object.keys(),Object.values()
- Advanced Array Methods:
reduce(),flat(),flatMap() - Function Methods:
call(),apply(),bind() - Promise Basics:
Promise.all(),async/await
- Advanced Patterns: Currying, Memoization, Composition
- Complex Promise Patterns: Retry logic, Circuit breakers
- Performance Optimization: Time complexity, Best practices
| File | Lines of Code | Key Concepts | Difficulty |
|---|---|---|---|
filter.js |
374 | Filtering, Predicates, Performance | ββ |
map.js |
255 | Transformation, Immutability | ββ |
reduce.js |
425 | Accumulation, Complex operations | βββ |
forEach.js |
330+ | Side effects, Iteration | β |
find.js |
380+ | Searching, Short-circuiting | ββ |
some-every.js |
400+ | Boolean testing, Validation | ββ |
sort.js |
450+ | Sorting algorithms, Comparators | βββ |
flat-flatMap.js |
380+ | Nested arrays, Flattening | ββ |
slice-splice.js |
450+ | Array manipulation, Mutation | ββ |
includes-indexOf.js |
430+ | Search methods, Performance | ββ |
- β Not just documentation - Working code examples
- β Custom implementations - Understand how methods work internally
- β Real-world use cases - Practical applications
- β Performance insights - Time/space complexity analysis
- β Best practices - Common pitfalls and how to avoid them
- β Comprehensive coverage - 100+ methods and patterns
- β Modern JavaScript - ES2015+ features and latest standards
- β Beginner to Advanced - Progressive learning path
You can also test these methods directly in your browser console:
// Open browser DevTools (F12)
// Copy and paste any example from the files
const numbers = [1, 2, 3, 4, 5];
const doubled = numbers.map(n => n * 2);
console.log(doubled); // [2, 4, 6, 8, 10]Contributions are welcome! Here's how you can help:
- β Star this repository
- π Report bugs or issues
- π‘ Suggest new methods or improvements
- π Improve documentation
- β¨ Add more examples and use cases
- π§ Fix typos or code improvements
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Beginners learning JavaScript fundamentals
- Intermediate developers looking to deepen their understanding
- Interview preparation - Common method questions
- Teachers/Educators - Teaching resources with examples
- Code reviewers - Reference for best practices
- Total Files: 10+ comprehensive implementations
- Total Examples: 200+ practical examples
- Methods Covered: 100+ JavaScript methods
- Lines of Code: 8,000+ lines of documented code
- Custom Implementations: 15+ from-scratch implementations
This project is open source and available under the MIT License.
If you find this repository helpful, please consider giving it a star! β
Made with β€οΈ for the JavaScript community
Happy coding! π