Can't run a spread operator outside of RunKit


#1

Hi Everyone,

I’ve got the following statement which I would like to run outside of Runkit:
_.flatMap(data.experiments, (values, index) => [{ experiment_id: index, ...values }])

This returns an array of objects that is exactly in the structure I need.

Since I was getting linting errors, I have tried transforming the code using babel (stage-2 preset) but now the result set is completely different than the one I get in Runkit.

Generated code:
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

const experimentsData = _.flatMap(body, (values, index) => [_extends({ experiment_id: index }, values)]);

Any idea on how I can make this code in any other environment other than Runkit?

Link to notebook: https://runkit.com/ferparra/lodash/2.0.0


#2

Forgot to JSON.parse(data)

Solved!!! Woooo!