Skip to content

Object to Array

This module converts a JavaScript object into an array using various configurable conversion modes. It supports six different modes: values (values only), keys (keys only), entries (key-value objects), entriesArray ([key, value] arrays), indexed (indexed objects with position), and numbered (sorting by numeric keys). It can optionally preserve the original object along with the converted result. It can also allow direct pass-through of data that is already arrays. It is essential for adapting data formats between modules that expect arrays and modules that produce objects.

ParameterTypeRequiredDescription
conversionModestringNoConversion mode: values, keys, entries, entriesArray, indexed, numbered. Default values.
keyNamestringNoProperty name for the key in entries and indexed modes. Default key.
valueNamestringNoProperty name for the value in entries and indexed modes. Default value.
preserveOriginalbooleanNoIf true, includes the original object along with the converted array. Default false.
allowArrayPassbooleanNoIf true, allows arrays to pass through unmodified. If false and the input is an array, returns an error. Default false.
{
"nextModule": "siguiente_modulo",
"data": [
{ "key": "nombre", "value": "Juan" },
{ "key": "edad", "value": 30 }
],
"_meta_": {
"originalType": "object",
"conversionMode": "entries",
"originalKeysCount": 2,
"resultingLength": 2,
"description": "Convertido a array de objetos con propiedades 'key' y 'value'"
}
}
{
"conversionMode": "entries",
"keyName": "campo",
"valueName": "valor",
"preserveOriginal": false,
"allowArrayPass": true
}
  • values mode: returns Object.values(data) — values only
  • keys mode: returns Object.keys(data) — keys only
  • entries mode: returns objects with customizable properties for key and value
  • entriesArray mode: returns [key, value] arrays (Object.entries format)
  • indexed mode: like entries but adds an index field with the position
  • numbered mode: sorts keys numerically and returns values in that order (for numeric keys only)
  • If preserveOriginal is true, the output is { converted: [...], original: {...}, _meta_: {...} }
  • The _meta_ includes detailed information about the conversion performed
  • objectArrayConverter (bidirectional object/array conversion)
  • iterador (iterate over the resulting array)
  • mapFunction (transform each array element)