I'm learning JavaScript using W3C and I didn't find an answer to this question.
I'm trying to make some manipulations on array elements which fulfill some condition.
Is there a way to do it other than running on the array elements in for loop? Maybe something like (in other languages):
foreach (object t in tArray)
if (t follows some condition...) t++;
another thing, sometimes I want to use the element's value and sometimes I want to use it as a reference. what is the syntactical difference?
As well, I'll be happy for recommendations on more extensive sites to learn JavaScript from. thanks
In most browsers (not IE <= 8) arrays have a filter
method, which doesn't do quite what you want but does create you an array of elements of the original array that satisfy a certain condition:
function isGreaterThanFive(x) {
return x > 5;
}
[1, 10, 4, 6].filter(isGreaterThanFive); // Returns [10, 6]
Mozilla Developer Network has a lot of good JavaScript resources.