I have a piece of code which uses spread syntax.
On my main server, the node js version is 0.10. For some reason, it's not possible to upgrade node js. So I'm converting all the arrow functions such that they are compatible with the old version of node js. I'm not able to convert the spread operator.
I tried with Object.assign
but it keeps showing syntax error. I'm confused on how to convert spread operator to normal javascript code.
Here is my code :
senddata = Array.from({ ...data, length: Math.max(...Object.keys(data)) });
I'm finding it really confusing to convert this. In fact I'm just not able to understand where to add Object.assign and how to fix the syntax errors regarding it.
For arrow function I converted them like this:
with arrow function :
dag.get('obj')
.then((data) => {
run();
}, (err) => {
console.log(err)
})
without arrow function
dag.get('obj')
.then(function(data) {
run();
}, function(err) {
console.log(err)
})
But not able to convert spread syntax.
This is what I tried :
Object.assign({data},length: Math.max(Object.assign({Object},keys(data))
Moreover, how can I write the same code without using spread syntax or Object.assign ?
After referring to the answers and suggestions posted below,here is the code :
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
senddata = Array.from({ ...data,
length: Math.max.apply(Math, _toConsumableArray(Object.keys(data)))
});
But I still get an error for ...data