JQuery Several Ways to Filter an Array by Child Array

JQuery Array

There are many ways to filter an array, but we have to consider on the function performance. It might be not take an impact in short data, but it’ll in long data. Imagine if we have to manage many data collections in client site, the browser will be slow to render your web page or the user will be bored to wait the loading (until your data has been managed). The important thing is not only to consider the performance, but also to find the easiest way to use.

Before we try several ways to filter an array, we need the array data first. Each array data consist of parent and child element. Here is the code preparation :

Now, lest try several ways to filter an array. Some are using jQuery function ways and some are using javascript function ways :

  • JQuery = jQuery.grep

  •  JQuery = jQuery.each

  •  Javascript = For Loop

  •  Javascript = Array Filter

  •  javascript = forEach

All of those ways are easy. But it has different speed performance. You can follow this link JQuery grep vs For Loop Performance by Richard Kraaijenhagen. For me, if jQuery.grep has the best performance, i prefer to use it because this is the simplest one. Unfortunately the best performance is javascript for loop, so i always try to use it. 🙂

FatkhanFauzi About FatkhanFauzi

A passionate software engineer who wants to share anything that he learns and some of his life experiences. Want to know more about him? see Fatkhan Fauzi Profile


2 Comments

So, what do you think ?

Leave a Reply

%d bloggers like this: