Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
166
rated 0 times [  167] [ 1]  / answers: 1 / hits: 168869  / 14 Years ago, thu, september 23, 2010, 12:00:00

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


More From » arrays

 Answers
2

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.


[#95529] Tuesday, September 21, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
marinalyssak

Total Points: 637
Total Questions: 101
Total Answers: 94

Location: Morocco
Member since Fri, May 22, 2020
4 Years ago
;