From d6e0d0347ed9be01692ef2c49f3a73014792c8f7 Mon Sep 17 00:00:00 2001 From: Suyash Vashishtha <65910716+suyashvash@users.noreply.github.com> Date: Sat, 30 Jul 2022 14:45:24 +0530 Subject: [PATCH 1/2] Object to array conversion Added a function to convert an object to an array in JS. --- index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 62d7640..e1925fb 100644 --- a/index.js +++ b/index.js @@ -65,4 +65,11 @@ function array_frequency(arr) { return freq_obj; } -export { is_array, head, tail, in_array, array_filter, array_chunk, array_frequency }; +function object_to_array(obj){ + let temp=[] + const entries = Object.entries(obj) + entries.forEach(ent => temp.push(ent[1])) + return temp; +} + +export { is_array, head, tail, in_array, array_filter, array_chunk, array_frequency,object_to_array }; From 8bce0044fa2ab2085b6f7df1f0712ccdc799de56 Mon Sep 17 00:00:00 2001 From: Suyash Vashishtha <65910716+suyashvash@users.noreply.github.com> Date: Sat, 30 Jul 2022 14:49:36 +0530 Subject: [PATCH 2/2] Update Readme for object to array --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5f6ee5d..80cc80a 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,17 @@ npm i @hetarth02/js-array-helpers In your `package.json` add the following, `"type": "module"`. ```js -import { is_array } from "@hetarth02/js-array-helpers"; +import { is_array, object_to_array } from "@hetarth02/js-array-helpers"; let arr = [1, 2]; console.log(is_array(arr)); // true -``` \ No newline at end of file + + const objectX = { + 0:"Apple", + 1:"Microsoft", + 2:"Google" + } + + console.log(object_to_array(objectX)) // [ 'Apple', 'Microsoft', 'Google' ] + +```