Skip to content

Objects

objectToArray

1.0.0

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 alias
objToArr(/obj/);
  • Extracts all property values from an object into an array
  • Returns input unchanged if not an object
  • Has a convenient objToArr alias
  • 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
ArgTypeDefault ValueRequired
objany-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)); // 123
console.log(objectToArray(null)); // null
console.log(objectToArray(undefined)); // undefined

Working 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, 88
console.log(`Average: ${average}`); // Average: 90.5

Converting 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 values
const 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 processing
const formValues = objectToArray(formData);
// Check if any required fields are empty
const hasEmptyFields = formValues.some(value =>
value === '' || value === null || value === undefined
);
console.log('Form values:', formValues);
console.log('Has empty fields:', hasEmptyFields);

Project

Built with by Jo Santana in Brazil.

© 2026 Inpulse. All rights reserved.