Objects
objectToArray
1.0.0- Dependencies:
- ∟Direct: 0
- ∟Peer: 0
- Source code ↗
- Check on NPM ↗
Hidden
Overview
Section titled “Overview”Converts an object’s values to an array by extracting all property values. Returns the input unchanged if it’s not an object. This function has an alias named objToArr for convenience.
objectToArray(/obj/);// or using the aliasobjToArr(/obj/);Features
Section titled “Features”- Extracts all property values from an object into an array
- Returns input unchanged if not an object
- Has a convenient
objToArralias - Preserves original value types in the array
- Works with any object structure
- Simple and intuitive API
- No side effects - does not modify original object
- Comprehensive testing
Arguments
Section titled “Arguments”| Arg | Type | Default Value | Required |
obj | any | - | Yes |
Use the objectToArray() function to convert an object’s values to an array.
import { objectToArray } from '@inpulse-ui/utils';
const person = { name: 'John', age: 30, city: 'New York'};
const values = objectToArray(person);console.log(values); // ['John', 30, 'New York']Using the objToArr alias:
import { objToArr } from '@inpulse-ui/utils';
const config = { apiUrl: 'https://api.example.com', timeout: 5000, retries: 3};
const configValues = objToArr(config);console.log(configValues); // ['https://api.example.com', 5000, 3]Returns input unchanged for non-objects:
console.log(objectToArray('hello')); // 'hello'console.log(objectToArray(123)); // 123console.log(objectToArray(null)); // nullconsole.log(objectToArray(undefined)); // undefinedWorking with nested objects:
const user = { id: 1, profile: { name: 'Alice', email: 'alice@example.com' }, preferences: { theme: 'dark', notifications: true }};
const values = objectToArray(user);console.log(values);// [// 1,// { name: 'Alice', email: 'alice@example.com' },// { theme: 'dark', notifications: true }// ]Processing object values:
const scores = { math: 95, science: 87, english: 92, history: 88};
const scoreArray = objectToArray(scores);const average = scoreArray.reduce((sum, score) => sum + score, 0) / scoreArray.length;
console.log(`Scores: ${scoreArray.join(', ')}`); // Scores: 95, 87, 92, 88console.log(`Average: ${average}`); // Average: 90.5Converting API response data:
const apiResponse = { success: true, data: { users: 150, posts: 1200, comments: 3500 }, timestamp: '2023-10-09T10:30:00Z'};
const responseValues = objectToArray(apiResponse);console.log(responseValues);// [// true,// { users: 150, posts: 1200, comments: 3500 },// '2023-10-09T10:30:00Z'// ]
// Extract just the data valuesconst dataValues = objectToArray(apiResponse.data);console.log(dataValues); // [150, 1200, 3500]Form data processing:
const formData = { firstName: 'John', lastName: 'Doe', email: 'john.doe@example.com', age: 25, subscribe: true};
// Convert to array for validation or processingconst formValues = objectToArray(formData);
// Check if any required fields are emptyconst hasEmptyFields = formValues.some(value => value === '' || value === null || value === undefined);
console.log('Form values:', formValues);console.log('Has empty fields:', hasEmptyFields);Built with by Jo Santana in Brazil.
© 2026 Inpulse. All rights reserved.