jsmimic-php
is a JS library that allows you to mimic PHP functions in JavaScript. This library is useful for people who are familiar with PHP and want to use JavaScript but don't have the time to learn the JavaScript equivalents of PHP functions.
To install jsmimic-php:
npm install jsmimic-php
yarn add jsmimic-php
Note: Multi-dimensional arrays in php are represented as objects in JavaScript.
Example:
array(1, 2, array(3, 4)) // in phpis the same thing as ππ½
[1, 2, {0: 3, 1: 4}] // in JS.and
array('name' => 'John Doe', 'age' => 20) // in phpis the same thing as ππ½
{name: 'John Doe', age: 20} // in JS.This is because JavaScript arrays can only have numeric keys, while PHP arrays can have both numeric and string keys.
In more simple terms, JavaScript arrays can only have one dimension, while PHP arrays can have multiple dimensions, by multiple dimensions, I mean arrays within arrays or nested arrays.
but JavaScript arrays can only have arrays within objects, not arrays within arrays.
Not clear enough? π€
if you want to use multi-dimensional arrays in JavaScript, you can use objects instead and if you want to use objects in JavaScript, you can also use maps instead.
Example:
array('name' => 'John Doe', 'age' => 20) // in phpis the same thing as ππ½
new Map([['name', 'John Doe'], ['age', 20]]) // in JS. // or {name: 'John Doe', age: 20} // in JS.
pheew! π , that was a lot to take in, but I hope you understand now. π So let's officially get started. π
To use jsmimic-php, you must first import it into your project:
const jsmp = require('jsmimic-php');
// or
import jsmp from 'jsmimic-php';
or you can import the functions from the library individually:
const { array_chunk, array_combine, array_change_key_case } = require('jsmimic-php');
// or
import { array_chunk, array_combine, array_change_key_case } from 'jsmimic-php';
Then, you can use the functions in jsmimic-php: just like in PHP, but this time in JavaScript. π
// Example 1: Using the `array_combine` function
const keys = ['name', 'age'];
const values = ['John Doe', 20];
const arr = array_combine(keys, values); // { name: 'John Doe', age: 20 }
// Example 2: Using the `array_change_key_case` function
const arr = {
name: 'John Doe',
age: 20
};
const newArr = array_change_key_case(arr, 'CASE_UPPER'); // { NAME: 'John Doe', AGE: 20 }
// Example 3: Using the `array_chunk` function
const arr = [1, 2, 3, 4, 5];
const newArr = array_chunk(arr, 2); // [[1, 2], [3, 4], [5]]
Index | Function | Description | Example |
---|---|---|---|
1 | array_change_key_case | Changes all keys in an array to lowercase or uppercase. | Example |
2 | array_chunk | Split an array into chunks. | Example |
3 | array_column | Return the values from a single column in the input array. | Example |
4 | array_combine | Creates an array by using one array for keys and another for its values. | Example |
5 | array_count_values | Counts all the values of an array. | Example |
6 | array_diff_assoc | Computes the difference of arrays with additional index check. | Example |
7 | array_diff_key | Computes the difference of arrays using keys for comparison. | Example |
8 | array_diff_uassoc | Computes the difference of arrays with additional index check which is performed by a user supplied callback function. | Example |
9 | array_diff_ukey | Computes the difference of arrays using a callback function on the keys for comparison. | Example |
10 | array_diff | Computes the difference of arrays. | Example |
11 | array_fill_keys | Fill an array with values, specifying keys. | Example |
12 | array_fill | Fill an array with values. | Example |
13 | array_filter | Filters elements of an array using a callback function. | Example |
14 | array_flip | Exchanges all keys with their associated values in an array. | Example |
15 | array_intersect_assoc | Computes the intersection of arrays with additional index check. | Example |
16 | array_intersect_key | Computes the intersection of arrays using keys for comparison. | Example |
17 | array_intersect_uassoc | Computes the intersection of arrays with additional index check, compares indexes by a callback function. | Example |
18 | array_intersect_ukey | Computes the intersection of arrays using a callback function on the keys for comparison. | Example |
19 | array_intersect | Computes the intersection of arrays. | Example |
20 | array_is_list | Checks if the given array is a list. | Example |
21 | array_key_exists | Checks if the given key or index exists in the array. | Example |
22 | array_key_first | Gets the first key of an array. | Example |
23 | array_key_last | Gets the last key of an array. | Example |
24 | array_keys | Return all the keys or a subset of the keys of an array. | Example |
25 | array_map | Applies the callback to the elements of the given arrays. | Example |
26 | array_merge_recursive | Merge two or more arrays recursively. | Example |
27 | array_merge | Merge one or more arrays. | Example |
28 | array_multisort | Sort multiple or multi-dimensional arrays. | Example |
29 | array_pad | Pad array to the specified length with a value. | Example |
30 | array_product | Calculate the product of values in an array. | Example |
31 | array_push | Push one or more elements onto the end of array. | Example |
32 | array_rand | Pick one or more random keys out of an array. | Example |
33 | array_reduce | Iteratively reduce the array to a single value using a callback function. | Example |
34 | array_replace | Replaces elements from passed arrays into the first array. | Example |
35 | array_reverse | Return an array with elements in reverse order. | Example |
36 | array_search | Searches the array for a given value and returns the first corresponding key if successful. | Example |
37 | array_shift | Shift an element off the beginning of array. | Example |
38 | array_slice | Extract a slice of the array. | Example |
39 | array_splice | Remove a portion of the array and replace it with something else. | Example |
40 | array_sum | Calculate the sum of values in an array. | Example |
41 | array_udiff_assoc | Computes the difference of arrays with additional index check, compares data by a callback function. | Example |
42 | array_udiff_uassoc | Computes the difference of arrays with additional index check, compares data and indexes by a callback function. | Example |
43 | array_udiff | Computes the difference of arrays by using a callback function for data comparison. | Example |
44 | array_uintersect_assoc | Computes the intersection of arrays with additional index check, compares data by a callback function. | Example |
45 | array_uintersect_uassoc | Computes the intersection of arrays with additional index check, compares data and indexes by separate callback functions. | Example |
46 | array_uintersect | Computes the intersection of arrays, compares data by a callback function. | Example |
47 | array_unique | Removes duplicate values from an array. | Example |
48 | array_unshift | Prepend one or more elements to the beginning of an array. | Example |
49 | array_values | Return all the values of an array. | Example |
50 | array_walk_recursive | Apply a user function recursively to every member of an array. | Example |
51 | array_walk | Apply a user supplied function to every member of an array. | Example |
52 | array | Create an array. | Example |
53 | arsort | Sort an array in reverse order and maintain index association. | Example |
54 | asort | Sort an array and maintain index association. | Example |
55 | compact | Create array containing variables and their values. | Example |
56 | count | Count all elements in an array, or something in an object. | Example |
57 | current | Return the current element in an array. | Example |
58 | each | Return the current key and value pair from an array and advance the array cursor. | Example |
59 | end | Set the internal pointer of an array to its last element. | Example |
60 | in_array | Checks if a value exists in an array. | Example |
61 | key_exists | Alias of array_key_exists. | Example |
62 | key | Fetch a key from an array. | Example |
63 | krsort | Sort an array by key in reverse order. | Example |
64 | ksort | Sort an array by key. | Example |
65 | list | Assign variables as if they were an array. | Example |
66 | natcasesort | Sort an array using a case insensitive "natural order" algorithm. | Example |
67 | natsort | Sort an array using a "natural order" algorithm. | Example |
68 | next | Advance the internal array pointer of an array. | Example |
69 | range | Create an array containing a range of elements. | Example |
70 | reset | Set the internal pointer of an array to its first element. | Example |
71 | rsort | Sort an array in reverse order. | Example |
72 | shuffle | Shuffle an array. | Example |
73 | sizeof | Alias of count. | Example |
74 | sort | Sort an array. | Example |
75 | uasort | Sort an array with a user-defined comparison function and maintain index association. | Example |
76 | uksort | Sort an array by keys using a user-defined comparison function. | Example |
77 | usort | Sort an array by values using a user-defined comparison function. | Example |
- Add more functions from the PHP array functions
- Add more functions from other PHP functions for other data types like strings, integers, etc.
- Add more tests. π§ͺ
- Add more documentation. π
- Add more examples. π
The array_change_key_case function is used to change the case of all keys in an array to either uppercase or lowercase.
- array (Object): The input array whose keys you want to transform.
- case (String): The case transformation option. Use 'CASE_UPPER' to change keys to uppercase or 'CASE_LOWER' to change keys to lowercase.
const originalArray = {
name: 'John Doe',
age: 20
};
// Change keys to uppercase
const newArrayUpperCase = array_change_key_case(originalArray, 'CASE_UPPER'); // { NAME: 'John Doe', AGE: 20 }
// Change keys to lowercase
const newArrayLowerCase = array_change_key_case(originalArray, 'CASE_LOWER'); // { name: 'John Doe', age: 20 }
The array_change_key_case
function takes two parameters: the input array and the desired case transformation ('CASE_UPPER' for uppercase, 'CASE_LOWER' for lowercase).
It transforms the keys of the array to the specified case while preserving the original values.
The resulting array is an object where each key is a key from the original array and each value is a value from the original array.
The array_change_key_case
function is useful when you want to change the case of all keys in an array to either uppercase or lowercase.
The array_chunk function is used to split an array into smaller chunks, each containing a specified number of elements.
- array (Array): The input array to be chunked.
- size (Number): The size of each chunk.
- preserveKeys (Boolean): (Optional) If set to true, the function will preserve the original keys. Default is false.
Usage Example:
const originalArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const newArr = array_chunk(originalArray, 3); // [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]
// works with strings too
const textArray = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
const newTextArr = array_chunk(textArray, 4); // [['a', 'b', 'c', 'd'], ['e', 'f', 'g', 'h'], ['i', 'j']]
The array_chunk
function takes two parameters: the input array and the size of each chunk.
It divides the original array into smaller arrays, each containing the specified number of elements (except the last chunk, which may have fewer elements if there are not enough remaining).
The resulting array is a multidimensional array where each element is a chunk of the original array.
The array_chunk
function is useful when you want to split an array into smaller chunks.
This function returns the values from a single column in the input array.
- array (Array): The input array.
- columnKey (String): The column of values to return.
const arr = [
{ id: 1, name: 'John Doe', age: 20 },
{ id: 2, name: 'Jane Doe', age: 25 },
{ id: 3, name: 'Mary Doe', age: 30 },
{ id: 4, name: 'Mark Doe', age: 35 },
{ id: 5, name: 'Mike Doe', age: 40 },
];
const newArr = array_column(arr, 'name'); // ['John Doe', 'Jane Doe', 'Mary Doe', 'Mark Doe', 'Mike Doe']
The array_column
function takes two parameters: the input array and the column of values to return.
It returns the values from a single column in the input array.
The resulting array is an array of values from the specified column.
The array_column
function is useful when you want to return the values from a single column in the input array.
This function creates an array by using one array for keys and another for its values.
- keys (Array): Array of keys to be used. Illegal values for key will be converted to string.
- values (Array): Array of values to be used.
- preserveKeys (Boolean): (Optional) If set to true, the function will preserve the original keys. Default is false.
const keys = ['name', 'age'];
const values = ['John Doe', 20];
const arr = array_combine(keys, values); // { name: 'John Doe', age: 20 }
The array_combine
function takes two parameters: the array of keys and the array of values.
It creates an array by using the first array for keys and the second array for values.
The resulting array is an object where each key is a key from the first array and each value is a value from the second array.
The array_combine
function is useful when you want to create an associative array from two arrays.
This function counts all the values of an array.
- array (Array): The array of values to count.
const arr = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5];
const newArr = array_count_values(arr); // { '1': 2, '2': 2, '3': 2, '4': 2, '5': 2 }
The array_count_values
function takes one parameter: the array of values to count.
It counts all the values of the array and returns an object where each key is a value from the array and each value is the number of times that value appears in the array.
The array_count_values
function is useful when you want to count the number of occurrences of each value in an array.
This function computes the difference of arrays in array1 but not in array2 with additional index check.
- array1 (Array): The array to compare from.
- array2 (Array): An array to compare against.
const arr1 = [1, 2, 3, 4, 5, 8, 10, 11, 12];
const arr2 = [1, 2, 3, 4, 5, 6];
const newArr = array_diff_assoc(arr1, arr2); // [8, 10, 11, 12]
The array_diff_assoc
function takes two parameters: the array to compare from and the array to compare against.
It computes the difference of arrays in array1 but not in array2 with additional index check.
The resulting array is an array of values from array1 that are not in array2.
The array_diff_assoc
function is useful when you want to find the difference between two arrays with additional index check.
This function computes the difference of arrays that is in array1 but not in array2 using keys for comparison.
- array1 (Array): The array to compare from.
- array2 (Array): An array to compare against.
const array1 = { key1: 'value1', key2: 'value2', key3: 'value3' };
const array2 = { key2: 'value2', key4: 'value4', key5: 'value5' };
const newArr = array_diff_key(array1, array2); // { key1: 'value1', key3: 'value3' }
The array_diff_key
function takes two parameters: the array to compare from and the array to compare against.
It computes the difference of arrays that is in array1 but not in array2 using keys for comparison.
The resulting array is an object of values from array1 that are not in array2.
The array_diff_key
function is useful when you want to find the difference between two arrays using keys for comparison.
This function computes the difference of arrays with additional index check which is performed by a user supplied callback function.
- array1 (Array): The array to compare from.
- array2 (Array): An array to compare against.
- callback (Function): The callback function to use for comparison.
const arr1 = [1, 2, 3, 4, 5, 8, 10, 11, 12];
const arr2 = [1, 2, 3, 4, 5, 6];
const newArr = array_diff_uassoc(arr1, arr2, (a, b) => a - b); // [8, 10, 11, 12] sorted in ascending order
The array_diff_uassoc
function takes three parameters: the array to compare from, the array to compare against and the callback function to use for comparison.
It computes the difference of arrays with additional index check which is performed by a user supplied callback function.
The resulting array is an array of values from array1 that are not in array2.
The array_diff_uassoc
function is useful when you want to find the difference between two arrays with additional index check which is performed by a user supplied callback function.
This function computes the difference of arrays that is in array1 but not in array2 using a callback function on the keys for comparison.
- array1 (Array): The array to compare from.
- array2 (Array): An array to compare against.
- callback (Function): The callback function to use for comparison.
const dataset1 = { 'a': 'apple', 'b': 'banana', 'c': 'cherry' };
const dataset2 = { 'b': 'banana', 'd': 'date', 'e': 'elderberry' };
function customKeyCompare(a, b) {
return a.toLowerCase() === b.toLowerCase() ? 0 : -1;
}
const differentKeys = array_diff_ukey(dataset1, dataset2, customKeyCompare); // { 'a': 'apple', 'c': 'cherry' }
The array_diff_ukey
function takes three parameters: the array to compare from, the array to compare against and the callback function to use for comparison.
It computes the difference of arrays that is in array1 but not in array2 using a callback function on the keys for comparison.
The resulting array is an object of values from array1 that are not in array2.
The array_diff_ukey
function is useful when you want to find the difference between two arrays using a callback function on the keys for comparison.
This function computes the difference of arrays.
- array1 (Array): The array to compare from.
- array2 (Array): An array to compare against.
const arr1 = [1, 2, 3, 4, 5];
const arr2 = [4, 5, 6, 7, 8];
const newArr = array_diff(arr1, arr2); // [1, 2, 3]
The array_diff
function takes two parameters: the array to compare from and the array to compare against.
It computes the difference of arrays.
The resulting array is an array of values from array1 that are not in array2.
The array_diff
function is useful when you want to find the difference between two arrays.
This function fills an array with values, specifying keys.
- keys (Array): Array of values that will be used as keys.
- value (Any): Value to use for filling.
const arr = array_fill_keys(['foo', 5, 10, 'bar'], 'banana'); // { foo: 'banana', '5': 'banana', '10': 'banana', bar: 'banana' }
The array_fill_keys
function takes two parameters: the array of keys and the value to use for filling.
It fills an array with values, specifying keys.
The resulting array is an object where each key is a key from the first array and each value is the value to use for filling.
The array_fill_keys
function is useful when you want to fill an array with values, specifying keys.
This function fills an array with values.
- startIndex (Number): The first index of the returned array.
- num (Number): Number of elements to insert.
- value (Any): Value to use for filling.
const arr = array_fill(5, 6, 'banana'); // [ 'banana', 'banana', 'banana', 'banana', 'banana', 'banana' ]
const filledArray = array_fill(0, 5, 'default'); // [ 'default', 'default', 'default', 'default', 'default' ]
The array_fill
function takes three parameters: the first index of the returned array, the number of elements to insert and the value to use for filling.
It fills an array with values.
The resulting array is an array of values from array1 that are not in array2.
The array_fill
function is useful when you want to fill an array with values.
This function filters elements of an array using a callback function.
- array (Array): The array to iterate over.
- callback (Function): The callback function to use for filtering. If no callback is supplied, all entries of array equal to false will be removed.
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const newArr = array_filter(arr, (value) => value % 2 === 0); // [2, 4, 6, 8, 10]
The array_filter
function takes two parameters: the array to iterate over and the callback function to use for filtering.
It filters elements of an array using a callback function.
The resulting array is an array of values from array1 that are not in array2.
The array_filter
function is useful when you want to filter elements of an array using a callback function.
This function exchanges all keys with their associated values in an array.
- array (Array): The array of key/value pairs to be flipped.
const arr = { name: 'John Doe', age: 20 };
const newArr = array_flip(arr); // { 'John Doe': 'name', '20': 'age' }
The array_flip
function takes one parameter: the array of key/value pairs to be flipped.
It exchanges all keys with their associated values in an array.
The resulting array is an object where each key is a value from the first array and each value is a key from the first array.
The array_flip
function is useful when you want to exchange all keys with their associated values in an array.
This function computes the intersection of arrays with additional index check.
- array1 (Array): The array to compare from.
- array2 (Array): An array to compare against.
const arr1 = [1, 2, 3, 4, 5, 8, 10, 11, 12];
const arr2 = [1, 2, 3, 4, 5, 6];
const newArr = array_intersect_assoc(arr1, arr2); // [1, 2, 3, 4, 5]
The array_intersect_assoc
function takes two parameters: the array to compare from and the array to compare against.
It computes the intersection of arrays with additional index check.
The resulting array is an array of values from array1 that are also in array2.
The array_intersect_assoc
function is useful when you want to find the intersection between two arrays with additional index check.
This function computes the intersection of arrays using keys for comparison.
- array1 (Array): The array to compare from.
- array2 (Array): An array to compare against.
const array1 = { key1: 'value1', key2: 'value2', key3: 'value3' };
const array2 = { key2: 'value2', key4: 'value4', key5: 'value5' };
const newArr = array_intersect_key(array1, array2); // { key2: 'value2' }
The array_intersect_key
function takes two parameters: the array to compare from and the array to compare against.
It computes the intersection of arrays using keys for comparison.
The resulting array is an object of values from array1 that are also in array2.
The array_intersect_key
function is useful when you want to find the intersection between two arrays using keys for comparison.
This function computes the intersection of arrays with additional index check, compares indexes by a callback function.
- array1 (Array): The array to compare from.
- array2 (Array): An array to compare against.
- callback (Function): The callback function to use for comparison.
const arr1 = [1, 2, 3, 4, 5, 8, 10, 11, 12];
const arr2 = [1, 2, 3, 4, 5, 6];
const newArr = array_intersect_uassoc(arr1, arr2, (a, b) => a - b); // [1, 2, 3, 4, 5] sorted in ascending order
The array_intersect_uassoc
function takes three parameters: the array to compare from, the array to compare against and the callback function to use for comparison.
It computes the intersection of arrays with additional index check, compares indexes by a callback function.
The resulting array is an array of values from array1 that are also in array2.
The array_intersect_uassoc
function is useful when you want to find the intersection between two arrays with additional index check, compares indexes by a callback function.
This function computes the intersection of arrays using a callback function on the keys for comparison.
- array1 (Array): The array to compare from.
- array2 (Array): An array to compare against.
- callback (Function): The callback function to use for comparison.
const dataset1 = { 'a': 'apple', 'b': 'banana', 'c': 'cherry' };
const dataset2 = { 'b': 'banana', 'd': 'date', 'e': 'elderberry' };
function customKeyCompare(a, b) {
return a.toLowerCase() === b.toLowerCase() ? 0 : -1;
}
const differentKeys = array_intersect_ukey(dataset1, dataset2, customKeyCompare); // { 'b': 'banana' }
The array_intersect_ukey
function takes three parameters: the array to compare from, the array to compare against and the callback function to use for comparison.
It computes the intersection of arrays using a callback function on the keys for comparison.
The resulting array is an object of values from array1 that are also in array2.
The array_intersect_ukey
function is useful when you want to find the intersection between two arrays using a callback function on the keys for comparison.
This function computes the intersection of arrays.
- array1 (Array): The array to compare from.
- array2 (Array): An array to compare against.
const arr1 = [1, 2, 3, 4, 5];
const arr2 = [4, 5, 6, 7, 8];
const newArr = array_intersect(arr1, arr2); // [4, 5]
The array_intersect
function takes two parameters: the array to compare from and the array to compare against.
It computes the intersection of arrays.
The resulting array is an array of values from array1 that are also in array2.
The array_intersect
function is useful when you want to find the intersection between two arrays.
This function checks if the given array is a list and returns true if the array is a list and false otherwise.
- array (Array): The array to check.
const arr = [1, 2, 3, 4, 5];
const isList = array_is_list(arr); // true
The array_is_list
function takes one parameter: the array to check.
It checks if the given array is a list and returns true if the array is a list and false otherwise.
The array_is_list
function is useful when you want to check if the given array is a list.
This function checks if the given key or index exists in the array.
- key (String): Value to check.
- array (Array): An array with keys to check.
const arr = { name: 'John Doe', age: 20 };
const keyExists = array_key_exists('name', arr); // true
The array_key_exists
function takes two parameters: the key to check and the array with keys to check.
It checks if the given key or index exists in the array and returns true if the key exists and false otherwise.
The array_key_exists
function is useful when you want to check if the given key or index exists in the array.
This function gets the first key of an array.
- array (Array): The array to get the first key from.
const arr = { name: 'John Doe', age: 20 };
const firstKey = array_key_first(arr); // 'name'
The array_key_first
function takes one parameter: the array to get the first key from.
It gets the first key of an array and returns the key.
The array_key_first
function is useful when you want to get the first key of an array.
This function gets the last key of an array.
- array (Array): The array to get the last key from.
const arr = { name: 'John Doe', age: 20 };
const lastKey = array_key_last(arr); // 'age'
The array_key_last
function takes one parameter: the array to get the last key from.
It gets the last key of an array and returns the key.
The array_key_last
function is useful when you want to get the last key of an array.
This function returns all the keys or a subset of the keys of an array.
- array (Array): The array to get the keys from.
const arr = { name: 'John Doe', age: 20 };
const keys = array_keys(arr); // ['name', 'age']
The array_keys
function takes one parameter: the array to get the keys from.
It returns all the keys or a subset of the keys of an array.
The array_keys
function is useful when you want to get all the keys or a subset of the keys of an array.
This function applies a callback function to each element of an array and returns the resulting array.
- callback (Function): The callback function to use for mapping.
- array (Array): The array to iterate over.
const arr = [1, 2, 3, 4, 5];
const newArr = array_map((value) => value * 2, arr); // [2, 4, 6, 8, 10]
The array_map
function takes two parameters: the callback function to use for mapping and the array to iterate over.
It applies a callback function to each element of an array and returns the resulting array.
The array_map
function is useful when you want to apply a callback function to each element of an array and return the resulting array.
This function merges two or more arrays recursively.
- array1 (Array): The first array to merge.
- array2 (Array): The second array to merge.
- ...arrays (Array): (Optional) The arrays to merge.
const arr1 = { name: 'John Doe', age: 20 };
const arr2 = { name: 'Jane Doe', age: 21 };
const mergedArr = array_merge_recursive(arr1, arr2); // { name: ['John Doe', 'Jane Doe'], age: [20, 21] }
The array_merge_recursive
function takes two or more parameters: the arrays to merge.
It merges two or more arrays recursively.
The resulting array is an object where each key is a key from the first array and each value is an array of values from the merged arrays.
The array_merge_recursive
function is useful when you want to merge two or more arrays recursively.
This function merges two or more arrays.
- array1 (Array): The first array to merge.
- array2 (Array): The second array to merge.
- ...arrays (Array): (Optional) The arrays to merge.
const arr1 = { name: 'John Doe', age: 20 };
const arr2 = { name: 'Jane Doe', age: 21 };
const mergedArr = array_merge(arr1, arr2); // { name: 'Jane Doe', age: 21 }
The array_merge
function takes two or more parameters: the arrays to merge.
It merges two or more arrays.
The resulting array is an object where each key is a key from the first array and each value is a value from the merged arrays.
The array_merge
function is useful when you want to merge two or more arrays.
This function sorts multiple or multi-dimensional arrays.
- array (Array): The array to sort.
- column (Object): The array of sorting columns descriptors. Each column descriptor has the following format: { column: 5, order: 'ASC' }.
const arr = [
{ name: 'John Doe', age: 20 },
{ name: 'Jane Doe', age: 21 },
{ name: 'James Doe', age: 22 },
{ name: 'Jenny Doe', age: 23 },
];
const sortedArr = array_multisort(arr, [{ column: 'age', order: 'ASC' }]);
// [{ name: 'John Doe', age: 20 }, { name: 'Jane Doe', age: 21 }, { name: 'James Doe', age: 22 }, { name: 'Jenny Doe', age: 23 }]
The array_multisort
function takes two parameters: the array to sort and the array of sorting columns descriptors.
It sorts multiple or multi-dimensional arrays.
The resulting array is an array of values from the first array sorted by the sorting columns descriptors.
The array_multisort
function is useful when you want to sort multiple or multi-dimensional arrays.
This function pads an array to a specified length with a specified value.
- array (Array): The array to pad.
- size (Number): The new size of the array.
- value (Any): Value to use for padding.
const arr = [1, 2, 3, 4, 5];
const newArr = array_pad(arr, 10, 'default');
// [1, 2, 3, 4, 5, 'default', 'default', 'default', 'default', 'default']
The array_pad
function takes three parameters: the array to pad, the new size of the array and the value to use for padding.
It pads an array to a specified length with a specified value.
The resulting array is an array of values from the first array padded to the specified length with the specified value.
The array_pad
function is useful when you want to pad an array to a specified length with a specified value.
This function calculates the product of values in an array.
- array (Array): The array to calculate the product of values from.
const arr = [1, 2, 3, 4, 5];
const product = array_product(arr); // 120
The array_product
function takes one parameter: the array to calculate the product of values from.
It calculates the product of values in an array.
The resulting array is an array of values from the first array with the last element removed.
The array_product
function is useful when you want to calculate the product of values in an array.
This function pushes one or more elements onto the end of an array.
- array (Array): The array to push elements to.
- ...elements (Any): The elements to push.
const arr = [1, 2, 3, 4, 5];
const newArr = array_push(arr, 6, 7, 8, 9, 10); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
The array_push
function takes two or more parameters: the array to push elements to and the elements to push.
It pushes one or more elements onto the end of an array.
The resulting array is an array of values from the first array with the pushed elements.
The array_push
function is useful when you want to push one or more elements onto the end of an array.
This function picks one or more random keys out of an array.
- array (Array): The array to pick random keys from.
- num (Number): (Optional) Specifies how many random keys to pick. Default is 1.
const arr = [1, 2, 3, 4, 5];
const randomKey = array_rand(arr); // 3
The array_rand
function takes one or two parameters: the array to pick random keys from and the number of random keys to pick.
It picks one or more random keys out of an array.
The resulting array is an array of random keys from the first array.
The array_rand
function is useful when you want to pick one or more random keys out of an array.
This function reduces an array to a single value by using a callback function.
- array (Array): The array to reduce.
- callback (Function): The callback function to use for reducing.
const arr = [1, 2, 3, 4, 5];
const sum = array_reduce(arr, (accumulator, currentValue) => accumulator + currentValue);
// 15
The array_reduce
function takes two parameters: the array to reduce and the callback function to use for reducing.
It reduces an array to a single value by using a callback function.
The resulting array is an array of values from the first array reduced to a single value by using a callback function.
The array_reduce
function is useful when you want to reduce an array to a single value by using a callback function.
This function replaces elements from passed arrays into the first array.
- array1 (Array): The array to replace elements in.
- array2 (Array): The array to replace elements from.
const arr1 = { name: 'John Doe', age: 20 };
const arr2 = { name: 'Jane Doe', age: 21 };
const replacedArr = array_replace(arr1, arr2);
// { name: 'Jane Doe', age: 21 }
The array_replace
function takes two parameters: the array to replace elements in and the array to replace elements from.
It replaces elements from passed arrays into the first array.
The resulting array is an object where each key is a key from the first array and each value is a value from the second array.
The array_replace
function is useful when you want to replace elements from passed arrays into the first array.
This function returns an array with elements in reverse order.
- array (Array): The array to reverse.
const arr = [1, 2, 3, 4, 5];
const reversedArr = array_reverse(arr);
// [5, 4, 3, 2, 1]
The array_reverse
function takes one parameter: the array to reverse.
It returns an array with elements in reverse order.
The resulting array is an array of values from the first array in reverse order.
The array_reverse
function is useful when you want to return an array with elements in reverse order.
This function searches an array for a given value and returns the corresponding key if successful.
- value (Any): The value to search for.
- array (Array): The array to search in.
const arr = { name: 'John Doe', age: 20 };
const key = array_search('John Doe', arr);
// 'name'
The array_search
function takes two parameters: the value to search for and the array to search in.
It searches an array for a given value and returns the corresponding key if successful.
The resulting array is an array of values from the first array in reverse order.
The array_search
function is useful when you want to search an array for a given value and return the corresponding key if successful.
This function shifts the first value of the array off and returns it.
- array (Array): The array to shift.
const arr = [1, 2, 3, 4, 5];
const shiftedValue = array_shift(arr);
// 1
The array_shift
function takes one parameter: the array to shift.
It shifts the first value of the array off and returns it.
The resulting array is an array of values from the first array with the first value removed.
The array_shift
function is useful when you want to shift the first value of the array off and return it.
This function returns a slice of the array.
- array (Array): The array to slice.
- offset (Number): The offset to start the slice from.
- length (Number): (Optional) The length of the slice. If length is omitted, the slice will have everything from offset up until the end of the array.
const arr = [1, 2, 3, 4, 5];
const slicedArr = array_slice(arr, 2, 2);
// [3, 4]
The array_slice
function takes two or three parameters: the array to slice, the offset to start the slice from and the length of the slice.
It returns a slice of the array.
The resulting array is an array of values from the first array sliced from the offset to the length.
The array_slice
function is useful when you want to return a slice of the array.
This function removes a portion of the array and replaces it with something else.
- array (Array): The array to splice.
- start (Number): The index at which to start changing the array.
- deleteCount (Number): (Optional) The number of elements in the array to remove from start.
- elements (Any): (Optional) The elements to add to the array from start.
const arr = [1, 2, 3, 4, 5];
const splicedArr = array_splice(arr, 2, 2, 6, 7, 8, 9, 10);
// [1, 2, 6, 7, 8, 9, 10, 5]
The array_splice
function takes three or more parameters: the array to splice, the index at which to start changing the array, the number of elements in the array to remove from start and the elements to add to the array from start.
It removes a portion of the array and replaces it with something else.
The resulting array is an array of values from the first array with the spliced elements.
The array_splice
function is useful when you want to remove a portion of the array and replace it with something else.
This function calculates the sum of values in an array.
- array (Array): The array to calculate the sum of values from.
const arr = [1, 2, 3, 4, 5];
const sum = array_sum(arr); // 15
The array_sum
function takes one parameter: the array to calculate the sum of values from.
It calculates the sum of values in an array.
The resulting array is an array of values from the first array with the last element removed.
The array_sum
function is useful when you want to calculate the sum of values in an array.
This function computes the difference of arrays with additional index check, compares data by a callback function.
- array1 (Array): The array to compare from.
- array2 (Array): An array to compare against.
- callback (Function): The callback function to use for comparison.
const arr1 = [1, 2, 3, 4, 5, 8, 10, 11, 12];
const arr2 = [1, 2, 3, 4, 5, 6];
const newArr = array_udiff_assoc(arr1, arr2, (a, b) => a - b); // [8, 10, 11, 12] sorted in ascending order
The array_udiff_assoc
function takes three parameters: the array to compare from, the array to compare against and the callback function to use for comparison.
It computes the difference of arrays with additional index check, compares data by a callback function.
The resulting array is an array of values from array1 that are not in array2.
The array_udiff_assoc
function is useful when you want to find the difference between two arrays with additional index check, compares data by a callback function.
This function computes the difference of arrays with additional index check, compares data and indexes by a callback function.
- array1 (Array): The array to compare from.
- array2 (Array): An array to compare against.
- dataCompareCallback (Function): The callback function to use for data comparison.
- indexCompareCallback (Function): The callback function to use for index comparison.
const arr1 = [1, 2, 3, 4, 5, 8, 10, 11, 12];
const arr2 = [1, 2, 3, 4, 5, 6];
const newArr = array_udiff_uassoc(arr1, arr2, (a, b) => a - b, (a, b) => a - b);
// [8, 10, 11, 12] sorted in ascending order
The array_udiff_uassoc
function takes four parameters: the array to compare from, the array to compare against, the callback function to use for data comparison and the callback function to use for index comparison.
It computes the difference of arrays with additional index check, compares data and indexes by a callback function.
The resulting array is an array of values from array1 that are not in array2.
The array_udiff_uassoc
function is useful when you want to find the difference between two arrays with additional index check, compares data and indexes by a callback function.
This function computes the difference of arrays by using a callback function for data comparison.
- array1 (Array): The array to compare from.
- array2 (Array): An array to compare against.
- callback (Function): The callback function to use for data comparison.
const arr1 = [1, 2, 3, 4, 5, 8, 10, 11, 12];
const arr2 = [1, 2, 3, 4, 5, 6];
const newArr = array_udiff(arr1, arr2, (a, b) => a - b);
// [8, 10, 11, 12] sorted in ascending order
The array_udiff
function takes three parameters: the array to compare from, the array to compare against and the callback function to use for data comparison.
It computes the difference of arrays by using a callback function for data comparison.
The resulting array is an array of values from array1 that are not in array2.
The array_udiff
function is useful when you want to find the difference between two arrays by using a callback function for data comparison.
This function computes the intersection of arrays with additional index check, compares data by a callback function.
- array1 (Array): The array to compare from.
- array2 (Array): An array to compare against.
- callback (Function): The callback function to use for data comparison.
const arr1 = [1, 2, 3, 4, 5, 8, 10, 11, 12];
const arr2 = [1, 2, 3, 4, 5, 6];
const newArr = array_uintersect_assoc(arr1, arr2, (a, b) => a - b);
// [1, 2, 3, 4, 5] sorted in ascending order
The array_uintersect_assoc
function takes three parameters: the array to compare from, the array to compare against and the callback function to use for data comparison.
It computes the intersection of arrays with additional index check, compares data by a callback function.
The resulting array is an array of values from array1 that are also in array2.
The array_uintersect_assoc
function is useful when you want to find the intersection between two arrays with additional index check, compares data by a callback function.
This function computes the intersection of arrays with additional index check, compares data and indexes by a callback function.
- array1 (Array): The array to compare from.
- array2 (Array): An array to compare against.
- dataCompareCallback (Function): The callback function to use for data comparison.
- indexCompareCallback (Function): The callback function to use for index comparison.
const arr1 = [1, 2, 3, 4, 5, 8, 10, 11, 12];
const arr2 = [1, 2, 3, 4, 5, 6];
const newArr = array_uintersect_uassoc(arr1, arr2, (a, b) => a - b, (a, b) => a - b);
// [1, 2, 3, 4, 5] sorted in ascending order
The array_uintersect_uassoc
function takes four parameters: the array to compare from, the array to compare against, the callback function to use for data comparison and the callback function to use for index comparison.
It computes the intersection of arrays with additional index check, compares data and indexes by a callback function.
The resulting array is an array of values from array1 that are also in array2.
The array_uintersect_uassoc
function is useful when you want to find the intersection between two arrays with additional index check, compares data and indexes by a callback function.
This function computes the intersection of arrays by using a callback function for data comparison.
- array1 (Array): The array to compare from.
- array2 (Array): An array to compare against.
- callback (Function): The callback function to use for data comparison.
const arr1 = [1, 2, 3, 4, 5, 8, 10, 11, 12];
const arr2 = [1, 2, 3, 4, 5, 6];
const newArr = array_uintersect(arr1, arr2, (a, b) => a - b);
// [1, 2, 3, 4, 5] sorted in ascending order
The array_uintersect
function takes three parameters: the array to compare from, the array to compare against and the callback function to use for data comparison.
It computes the intersection of arrays by using a callback function for data comparison.
The resulting array is an array of values from array1 that are also in array2.
The array_uintersect
function is useful when you want to find the intersection between two arrays by using a callback function for data comparison.
This function removes duplicate values from an array.
- array (Array): The array to remove duplicate values from.
const arr = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1];
const uniqueArr = array_unique(arr);
The array_unique
function takes one parameter: the array to remove duplicate values from.
It removes duplicate values from an array.
The resulting array is an array of values from the first array with duplicate values removed.
The array_unique
function is useful when you want to remove duplicate values from an array.
This function prepends one or more elements to the beginning of an array.
- array (Array): The array to prepend elements to.
- ...elements (Any): The elements to prepend.
const arr = [1, 2, 3, 4, 5];
const newArr = array_unshift(arr, 6, 7, 8, 9, 10);
// [6, 7, 8, 9, 10, 1, 2, 3, 4, 5]
The array_unshift
function takes two or more parameters: the array to prepend elements to and the elements to prepend.
It prepends one or more elements to the beginning of an array.
The resulting array is an array of values from the first array with the prepended elements.
The array_unshift
function is useful when you want to prepend one or more elements to the beginning of an array.
This function returns all the values of an array.
- array (Array): The array to get the values from.
const arr = { name: 'John Doe', age: 20 };
const values = array_values(arr); // ['John Doe', 20]
The array_values
function takes one parameter: the array to get the values from.
It returns all the values of an array.
The resulting array is an array of values from the first array.
The array_values
function is useful when you want to get all the values of an array.
This function applies a user function recursively to every member of an array.
- array (Array): The array to apply the callback function to.
- callback (Function): The callback function to apply.
const arr = [1, 2, 3, 4, 5];
const newArr = array_walk_recursive(arr, (value, key) => console.log(value, key));
// 1 0
The array_walk_recursive
function takes two parameters: the array to apply the callback function to and the callback function to apply.
It applies a user function recursively to every member of an array.
The resulting array is an array of values from the first array with the callback function applied to each value.
The array_walk_recursive
function is useful when you want to apply a user function recursively to every member of an array.
This function applies a user function to every member of an array.
- array (Array): The array to apply the callback function to.
- callback (Function): The callback function to apply.
const arr = [1, 2, 3, 4, 5];
const newArr = array_walk(arr, (value, key) => console.log(value, key));
// 1 0
The array_walk
function takes two parameters: the array to apply the callback function to and the callback function to apply.
It applies a user function to every member of an array.
The resulting array is an array of values from the first array with the callback function applied to each value.
The array_walk
function is useful when you want to apply a user function to every member of an array.
This function creates an array.
- ...elements (Any): The elements to add to the array.
const arr = array(1, 2, 3, 4, 5);
// [1, 2, 3, 4, 5]
The array
function takes one or more parameters: the elements to add to the array.
It creates an array.
The resulting array is an array of values from the parameters.
The array
function is useful when you want to create an array.
This function sorts an array in reverse order and maintains index association.
- array (Array): The array to sort.
const arr = [1, 2, 3, 4, 5];
const sortedArr = arsort(arr);
// [5, 4, 3, 2, 1]
The arsort
function takes one parameter: the array to sort.
It sorts an array in reverse order and maintains index association.
The resulting array is an array of values from the first array sorted in reverse order.
The arsort
function is useful when you want to sort an array in reverse order and maintain index association.
This function sorts an array and maintains index association.
- array (Array): The array to sort.
const arr = [1, 2, 3, 4, 5];
const sortedArr = asort(arr);
// [1, 2, 3, 4, 5]
The asort
function takes one parameter: the array to sort.
It sorts an array and maintains index association.
The resulting array is an array of values from the first array sorted.
The asort
function is useful when you want to sort an array and maintain index association.
This function creates an array containing variables and their values.
- ...variables (Any): The variables to add to the array.
const name = 'John Doe';
const age = 20;
const arr = compact(name, age);
// { name: 'John Doe', age: 20 }
The compact
function takes one or more parameters: the variables to add to the array.
It creates an array containing variables and their values.
The resulting array is an array of values from the parameters.
The compact
function is useful when you want to create an array containing variables and their values.
This function counts all elements in an array or something in an object.
- array (Array): The array to count elements from.
const arr = [1, 2, 3, 4, 5];
const count = count(arr);
// 5
The count
function takes one parameter: the array to count elements from.
It counts all elements in an array or something in an object.
The resulting array is an array of values from the first array with the callback function applied to each value.
The count
function is useful when you want to count all elements in an array or something in an object.
This function returns the current element in an array.
- array (Array): The array to get the current element from.
const arr = [1, 2, 3, 4, 5];
const currentElement = current(arr);
// 1
The current
function takes one parameter: the array to get the current element from.
It returns the current element in an array.
The resulting array is an array of values from the first array with the callback function applied to each value.
The current
function is useful when you want to return the current element in an array.
This function returns the current element in an array.
- array (Array): The array to get the current element from.
const arr = [1, 2, 3, 4, 5];
const currentElement = each(arr);
// 1
The each
function takes one parameter: the array to get the current element from.
It returns the current element in an array.
The resulting array is an array of values from the first array with the callback function applied to each value.
The each
function is useful when you want to return the current element in an array.
This function returns the last element in an array.
- array (Array): The array to get the last element from.
const arr = [1, 2, 3, 4, 5];
const lastElement = end(arr);
// 5
The end
function takes one parameter: the array to get the last element from.
It returns the last element in an array.
The resulting array is an array of values from the first array with the callback function applied to each value.
The end
function is useful when you want to return the last element in an array.
This function checks if a value exists in an array.
- value (Any): The value to check for.
- array (Array): The array to check in.
const arr = [1, 2, 3, 4, 5];
const exists = in_array(3, arr);
// true
The in_array
function takes two parameters: the value to check for and the array to check in.
It checks if a value exists in an array.
The resulting array is an array of values from the first array with the callback function applied to each value.
The in_array
function is useful when you want to check if a value exists in an array.
This function checks if a key exists in an array.
- key (Any): The key to check for.
- array (Array): The array to check in.
const arr = { name: 'John Doe', age: 20 };
const exists = key_exists('name', arr);
// true
The key_exists
function takes two parameters: the key to check for and the array to check in.
It checks if a key exists in an array.
The resulting array is an array of values from the first array with the callback function applied to each value.
The key_exists
function is useful when you want to check if a key exists in an array.
This function sorts an array by key in reverse order.
- array (Array): The array to sort.
const arr = [1, 2, 3, 4, 5];
const sortedArr = krsort(arr);
// [5, 4, 3, 2, 1]
The krsort
function takes one parameter: the array to sort.
It sorts an array by key in reverse order.
The resulting array is an array of values from the first array sorted by key in reverse order.
The krsort
function is useful when you want to sort an array by key in reverse order.
This function sorts an array by key.
- array (Array): The array to sort.
const arr = [1, 2, 3, 4, 5];
const sortedArr = ksort(arr);
// [1, 2, 3, 4, 5]
The ksort
function takes one parameter: the array to sort.
It sorts an array by key.
The resulting array is an array of values from the first array sorted by key.
The ksort
function is useful when you want to sort an array by key.
This function assigns variables as if they were an array.
- ...variables (Any): The variables to assign.
const arr = [1, 2, 3, 4, 5];
const [a, b, c, d, e] = List(...arr);
// a = 1, b = 2, c = 3, d = 4, e = 5
The List
function takes one or more parameters: the variables to assign.
It assigns variables as if they were an array.
The resulting array is an array of values from the parameters.
The List
function is useful when you want to assign variables as if they were an array.
This function sorts an array using a case insensitive "natural order" algorithm.
- array (Array): The array to sort.
const arr = [1, 2, 3, 4, 5];
const sortedArr = natcasesort(arr);
// [1, 2, 3, 4, 5]
The natcasesort
function takes one parameter: the array to sort.
It sorts an array using a case insensitive "natural order" algorithm.
The resulting array is an array of values from the first array sorted using a case insensitive "natural order" algorithm.
The natcasesort
function is useful when you want to sort an array using a case insensitive "natural order" algorithm.
This function sorts an array using a "natural order" algorithm.
- array (Array): The array to sort.
const arr = [1, 2, 3, 4, 5];
const sortedArr = natsort(arr);
The natsort
function takes one parameter: the array to sort.
It sorts an array using a "natural order" algorithm.
The resulting array is an array of values from the first array sorted using a "natural order" algorithm.
The natsort
function is useful when you want to sort an array using a "natural order" algorithm.
This function advances the internal pointer of an array.
- array (Array): The array to advance the internal pointer of.
const arr = [1, 2, 3, 4, 5];
const nextElement = next(arr);
The next
function takes one parameter: the array to advance the internal pointer of.
It advances the internal pointer of an array.
The resulting array is an array of values from the first array with the callback function applied to each value.
The next
function is useful when you want to advance the internal pointer of an array.
This function resets the internal pointer of an array.
- array (Array): The array to reset the internal pointer of.
const arr = [1, 2, 3, 4, 5];
const resetElement = reset(arr);
// 1
The reset
function takes one parameter: the array to reset the internal pointer of.
It resets the internal pointer of an array.
The resulting array is an array of values from the first array with the callback function applied to each value.
The reset
function is useful when you want to reset the internal pointer of an array.
This function sorts an array in reverse order.
- array (Array): The array to sort.
const arr = [1, 2, 3, 4, 5];
const sortedArr = rsort(arr);
// [5, 4, 3, 2, 1]
The rsort
function takes one parameter: the array to sort.
It sorts an array in reverse order.
The resulting array is an array of values from the first array sorted in reverse order.
The rsort
function is useful when you want to sort an array in reverse order.
This function shuffles an array.
- array (Array): The array to shuffle.
const arr = [1, 2, 3, 4, 5];
const shuffledArr = shuffle(arr);
// [1, 3, 2, 5, 4]
The shuffle
function takes one parameter: the array to shuffle.
It shuffles an array.
The resulting array is an array of values from the first array shuffled.
The shuffle
function is useful when you want to shuffle an array.
This function counts all elements in an array or something in an object.
- array (Array): The array to count elements from.
const arr = [1, 2, 3, 4, 5];
// 5
The sizeof
function takes one parameter: the array to count elements from.
It counts all elements in an array or something in an object.
The resulting array is an array of values from the first array with the callback function applied to each value.
The sizeof
function is useful when you want to count all elements in an array or something in an object.
This function sorts an array.
- array (Array): The array to sort.
const arr = [1, 2, 3, 4, 5];
const sortedArr = sort(arr);
// [1, 2, 3, 4, 5]
The sort
function takes one parameter: the array to sort.
It sorts an array.
The resulting array is an array of values from the first array sorted.
The sort
function is useful when you want to sort an array.
This function sorts an array with a user-defined comparison function and maintains index association.
- array (Array): The array to sort.
- callback (Function): The callback function to use for comparison.
const arr = { name: 'John Doe', age: 20, height: 1.8 };
const sortedArr = uasort(arr, (a, b) => a - b);
// { height: 1.8, age: 20, name: 'John Doe' }
The uasort
function takes two parameters: the array to sort and the callback function to use for comparison.
It sorts an array with a user-defined comparison function and maintains index association.
The resulting array is an array of values from the first array sorted with the callback function applied to each value.
The uasort
function is useful when you want to sort an array with a user-defined comparison function and maintain index association.
This function sorts an array by keys using a user-defined comparison function.
- array (Array): The array to sort.
- callback (Function): The callback function to use for comparison.
const arr = { name: 'John Doe', age: 20, height: 1.8 };
const sortedArr = uksort(arr, (a, b) => a - b);
// { age: 20, height: 1.8, name: 'John Doe' }
The uksort
function takes two parameters: the array to sort and the callback function to use for comparison.
It sorts an array by keys using a user-defined comparison function.
The resulting array is an array of values from the first array sorted with the callback function applied to each value.
The uksort
function is useful when you want to sort an array by keys using a user-defined comparison function.
This function sorts an array using a user-defined comparison function.
- array (Array): The array to sort.
- callback (Function): The callback function to use for comparison.
const arr = [1, 2, 3, 4, 5];
const sortedArr = usort(arr, (a, b) => a - b);
The usort
function takes two parameters: the array to sort and the callback function to use for comparison.
It sorts an array using a user-defined comparison function.
The resulting array is an array of values from the first array sorted with the callback function applied to each value.
The usort
function is useful when you want to sort an array using a user-defined comparison function.
This function returns the current element in an array.
- array (Array): The array to get the current element from.
const arr = [1, 2, 3, 4, 5];
const currentElement = each(arr);
The each
function takes one parameter: the array to get the current element from.
It returns the current element in an array.
The resulting array is an array of values from the first array with the callback function applied to each value.
The each
function is useful when you want to return the current element in an array and also do something with it.
This function creates an array containing a range of elements.
- start (Number): The start of the range.
- end (Number): The end of the range.
- step (Number): The step of the range.
const arr = range(1, 10, 2);
// [1, 3, 5, 7, 9]
The range
function takes three parameters: the start of the range, the end of the range and the step of the range.
It creates an array containing a range of elements.
The resulting array is an array of values from the parameters.
The range
function is useful when you want to create an array containing a range of elements.
Contributions, issues and feature requests are welcome! π Feel free to check issues page.
To contribute to this project:
-
Fork this repository.
-
Create a branch:
git checkout -b <branch_name>
. -
Make your changes and commit them:
git commit -m '<commit_message>'
-
For commit message, use:
FIX: <your message>
for bug fixes orFEATURE: <your message>
for new features (new functions implementation etc.) at the start of your commit message.
For example,
FIX: array_chunk function not working as expected
orFEATURE: Added array_diff function
. -
Push to the original branch you created:
git push origin <project_name>/<branch_name>
-
Create the pull request.
- PHP for the inspiration.
π€ Bryan Ebeh
- Github: @Bryan-b
- Twitter: @la_codist
- Linkedin: Bryan Ebeh
- Email: [email protected]
Give a βοΈ if this project helped you!
Made with β€οΈ by Bryan π
This project is MIT licensed.