Click here to Skip to main content
12,754,745 members (34,549 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


6 bookmarked
Posted 5 May 2012

Easy JavaScript Generic List Implementation

, 5 May 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
A quick and easy JavaScript implementation of a Generic List with LINQ support.


Generic collections in .NET, in combination with LINQ, are powerful tools for the C# or VB.NET developer; however, nothing like it comes with JavaScript. This code provides the beginnings of a JavaScript implementation for a Generic List. Fortunately, due to JavaScript's flexibility, this can be achieved with a relatively small amount of code. 

Using the code 

The following public functions with a description of each are currently supported:

  • Add: Add an element to the end of the list.
  • ElementAt: Get the element at a specific index in the list.
  • Where: Return a copy of this List object with only the elements that meet the criteria.
  • FirstOrDefault: Return the first object in the list that meets the 'query' criteria or null if
  • Count: Return the number of elements in the list. 
  • OrderBy: Order (ascending) the objects in the list by the given object property name.
  • OrderByDescending: Order (descending) the objects in the list by the given object property
  • Data: Set the list data using the passed in array. 

Example of using Car objects to fill the List:

function Car(make, model)
    this.make = make;
    this.model = model;

var myList = new List();
myList.Add(new Car("Honda", "CR-V"));
myList.Add(new Car("Nissan", "Sentra"));
myList.Add(new Car("Honda", "Civic"));

var selList = myList.Where("make == 'Honda'").OrderByDescending("model");


Version 1 uploaded on May 4, 2012.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Shawn Lawsure
Software Developer (Senior) Diversified Business Communications
United States United States
For over 20 years I have worked in the Information Systems field as a full-time employee for a variety of local companies. Throughout this time I have had the privilege to work with many different technologies and languages from COBOL on IBM mainframes to C# in Silverlight. My most recent work has been developed using the entire .NET Framework stack including Windows Presentation Foundation, Windows Workflow Foundation, and Windows Communication Foundation. Prior to this I spent many years upgrading a COM and ASP-based application written in VB6 to .NET. In nearly all of the work I have been involved with in the past ten years I have played a lead role in the design as well as the development of the work.

.NET including WPF, WCF, WWF, and C#.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
S V Saichandra30-Aug-12 2:36
memberS V Saichandra30-Aug-12 2:36 
QuestionUpdated again Pin
jfriedman14-May-12 22:59
memberjfriedman14-May-12 22:59 
GeneralMy vote of 3 Pin
jfriedman6-May-12 6:49
memberjfriedman6-May-12 6:49 
QuestionI made some improvements Pin
jfriedman6-May-12 6:49
memberjfriedman6-May-12 6:49 
AnswerRe: I made some improvements Pin
Shawn Lawsure7-May-12 3:08
memberShawn Lawsure7-May-12 3:08 
GeneralRe: I made some improvements Pin
jfriedman7-May-12 3:58
memberjfriedman7-May-12 3:58 
GeneralRe: I made some improvements Pin
Shawn Lawsure7-May-12 4:48
memberShawn Lawsure7-May-12 4:48 
GeneralRe: I made some improvements Pin
jfriedman7-May-12 7:22
memberjfriedman7-May-12 7:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 5 May 2012
Article Copyright 2012 by Shawn Lawsure
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid