Difference in JavaScript Statements

I'm trying to work with someone else's old Retool project. They have this transformer:

Which looks to me like this:

And in turn looks like this:

Are these as equivalent as they appear, or is there some subtlety that I'm missing?

They are indeed doing the same thing for you. This is called chaining - you take the value passed from one function and use it directly in another without the need for the intermediate step of storing the results.

I find it pretty nifty a lot of times. Other times I find it difficult to comprehend. Nothing wrong with either method but I will often still fall back on the more verbose version as it is more instantly clear to me what is happening when I look at it again in a few months time. It is also easier to debug as I can set a breakpoint in my code and read the value of data in this case to see if that part of the logic is working.

I agree that often more verbose gives future me the advantage of understanding what present me was thinking. However, did you see the third version? It’s ridiculously simple and doesn’t seem to be confusing in the least.

Oh, for some reason that image didn’t show up until I refreshed the page. And I totally missed the point!

A query.data is an object of arrays. So .zip is an array and .customer_name (or whatever) is an array.

So your first two code samples convert data into an array of objects and then converts .zip back into an array where it was to begin with.

So yeah, go with the third if you just need an array of zip’s values!

1 Like