Help me please solve my problem. I’m using underscore.js lib and I have a snippet that demonstrates what problem I have:
var a = [4, 3, 2, 1];
var b = _(a).select(function(el){ return el>1; }).push(6);
console.log("b: "+b);
// b: 4
var c = _(a).select(function(el){ return el>1; });
c.push(6);
console.log("c: "+c);
// c: [4, 3, 2, 6]
What is going on? Why select() function returns something strange – like an object with integer keys. But when we put results of select() we can use array native methods again. Why? What is it?
I know that we can use native array methods inside of chain(), but snippet results is really strange…
That is because the push method returns the index at which the value was inserted into the array.
For more details see the push method documentation
The
bvariable is the same as: