Skip to content

Commit bb6b937

Browse files
authored
Merge pull request #2 from suyashvash/main
Object to array conversion
2 parents 74d876d + 8bce004 commit bb6b937

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,17 @@ npm i @hetarth02/js-array-helpers
1414
In your `package.json` add the following, `"type": "module"`.
1515

1616
```js
17-
import { is_array } from "@hetarth02/js-array-helpers";
17+
import { is_array, object_to_array } from "@hetarth02/js-array-helpers";
1818

1919
let arr = [1, 2];
2020
console.log(is_array(arr)); // true
21-
```
21+
22+
const objectX = {
23+
0:"Apple",
24+
1:"Microsoft",
25+
2:"Google"
26+
}
27+
28+
console.log(object_to_array(objectX)) // [ 'Apple', 'Microsoft', 'Google' ]
29+
30+
```

index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,11 @@ function array_frequency(arr) {
6565
return freq_obj;
6666
}
6767

68-
export { is_array, head, tail, in_array, array_filter, array_chunk, array_frequency };
68+
function object_to_array(obj){
69+
let temp=[]
70+
const entries = Object.entries(obj)
71+
entries.forEach(ent => temp.push(ent[1]))
72+
return temp;
73+
}
74+
75+
export { is_array, head, tail, in_array, array_filter, array_chunk, array_frequency,object_to_array };

0 commit comments

Comments
 (0)