Why am I getting [object object] error when trying to reference data from a previous step?

This topic was automatically generated from Slack. You can find the original thread here.

I’m trying to reference data from a previous step and I keep getting [object object]

It sounds like you’re trying to reference data from a previous step in your Pipedream workflow but are encountering an issue where the data is being represented as [object Object]. This typically happens when you’re trying to log or use an object directly in a context that expects a string. JavaScript converts the object to the string [object Object] in such cases. To properly reference and use data from a previous step, ensure you’re accessing the specific properties of the object you’re interested in. For example, if you have a step named previous_step that outputs an object like this: on { "id": 1, "name": "Bulbasaur", "type": "plant" } And you want to use the name and type properties in a subsequent step, you should reference those properties specifically: export default defineComponent({ async run({ steps, $ }) { const pokemonName = steps.previous_step.result.name; const pokemonType = steps.previous_step.result.type; console.log(`${pokemonName} is a ${pokemonType} type Pokemon`); }, }); In this example, previous_step should be replaced with the actual name of the step you’re trying to reference. Also, result should be replaced with the appropriate property name if the data you’re trying to access is structured differently. If you’re still encountering issues, it might be helpful to log the entire object you’re trying to access to ensure you understand its structure: ```
console.log(JSON.stringify(steps.previous_step.result, null, 2));

how can I use an array?

To use an array in Pipedream, you can incorporate it within a Node.js code step in your workflow. Arrays in JavaScript can be used to store multiple values in a single variable and can be manipulated using various methods. Here’s a basic example of how to define an array, add elements to it, and iterate over it: export default defineComponent({ async run({ steps, $ }) { // Define an array let fruits = ["Apple", "Banana", "Cherry"]; // Add an element to the end of the array fruits.push("Date"); // Iterate over the array and log each fruit fruits.forEach(fruit => { console.log(fruit); }); // Return the array return fruits; }, }); In this example, we start by defining an array named fruits with three elements. We then use the push method to add a new element (“Date”) to the end of the array. After that, we use the forEach method to iterate over the array and log each element to the console. Finally, we return the array, which can then be used in subsequent steps of your workflow. Arrays are versatile and can be used to store various types of data, including strings, numbers, and even objects. You can manipulate arrays using different methods like map, filter, reduce, and more, depending on your specific needs.