Skip to content

Commit f57505b

Browse files
authored
Merge pull request #8 from suyashvash/main
Added `search_in_array` function and updated readme
2 parents 672acef + 47bd652 commit f57505b

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,34 @@ npm i @hetarth02/js-array-helpers
1313

1414
In your `package.json` add the following, `"type": "module"`.
1515

16+
### is_array()
1617
```js
17-
import { is_array, object_to_array } from "@hetarth02/js-array-helpers";
18+
import { is_array, object_to_array ,search_in_array} from "@hetarth02/js-array-helpers";
1819

1920
let arr = [1, 2];
2021
console.log(is_array(arr)); // true
22+
```
2123

24+
### object_to_array
25+
```js
2226
const objectX = {
2327
0:"Apple",
2428
1:"Microsoft",
2529
2:"Google"
2630
}
2731

28-
console.log(object_to_array(objectX)) // [ 'Apple', 'Microsoft', 'Google' ]
32+
console.log(object_to_array(objectX)) // [ 'Apple', 'Microsoft', 'Google' ]
33+
34+
```
35+
36+
### search_in_array
37+
```js
38+
39+
const mang = [ 'Microsoft','apple','netflix','Google' ]
40+
41+
const result = search_in_array("app",mang);
42+
43+
console.log(result); // ['apple']
44+
2945

3046
```

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ function get_all_indexes(arr, val) {
9393
return indexes;
9494
}
9595

96+
function search_in_array(query,array) {
97+
return array.filter(item => item.toLowerCase().search(query.toLowerCase()) !== -1)
98+
}
99+
96100
export {
97101
head,
98102
tail,
@@ -103,4 +107,5 @@ export {
103107
array_frequency,
104108
object_to_array,
105109
get_all_indexes,
110+
search_in_array,
106111
};

0 commit comments

Comments
 (0)