Listing all objects that share a common variable in Javascript

Posted by ntgCleaner on Stack Overflow See other posts from Stack Overflow or by ntgCleaner
Published on 2012-09-20T21:36:35Z Indexed on 2012/09/20 21:37 UTC
Read the original article Hit count: 165

Filed under:
|

I'm not exactly sure how to ask this because I am just learning OOP in Javascript, but here it goes:

I am trying to be able to make a call (eventually be able to sort) for all objects with the same variable. Here's an example below:

function animal(name, numLegs, option2, option3){
    this.name = name;
    this.numLegs = numLegs;
    this.option2 = option2;
    this.option3 = option3;
}

var human = new animal(Human, 2, example1, example2);
var horse = new animal(Horse, 4, example1, example2);
var dog = new animal(Dog, 4, example1, example2);

Using this example, I would like to be able to do a console.log() and show all animal NAMES that have 4 legs. (Should only show Horse and Dog, of course...)

I eventually want to be able to make a drop-down list or a filtered search list with this information. I would do this with php and mySQL but I'm doing this for the sake of learning OOP in javascript.

I only ask here because I don't exactly know what to ask. Thank you!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about oop