Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 197573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:51:52+00:00 2026-05-11T16:51:52+00:00

I have this code: function Item(id, itemType, itemData, itemCategoryId, itemRank) { this.id = id;

  • 0

I have this code:

function Item(id, itemType, itemData, itemCategoryId, itemRank) {
    this.id = id;
    this.itemType = itemType;
    this.itemData = itemData;
    this.itemCategoryId = itemCategoryId;
    this.itemRank = itemRank;
}
function Category(id) {
    this.id = id;
}

And I want to write a function for the Item class which I give it the CategoryId and it will return all items objects with this Category id.

What’s the best way to do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:51:52+00:00Added an answer on May 11, 2026 at 4:51 pm

    I see no array….

    I would assume that there would be an items prototype (note that there are no classes in javascript), and it would look something like this:

    function Item(id, categoryId, data, rank) {
      this.id = id;
      this.categoryId = categoryId;
      this.data = data;
      this.rank = rank;
    }
    
    function Items() {
      this.items = [];
      this.findByCategory = function(categoryId) { 
        var result = [];
        for(var i=0;i<this.items.length;i++) {
           if (categoryId == this.items[i].categoryId) 
              result.push(this.items[i]);
        }
        return result;
      }
      this.add = function(id, categoryId, data, rank) {
        this.items.push(new Item(id, categoryId, data, rank));  
      }
    }
    
    var items = new Items();
    items.add(2, 0, null, null); 
    items.add(1, 1, null, null); // I'm not going to care about data and rank here
    items.add(2, 1, null, null); 
    items.add(3, 1, null, null); 
    items.add(4, 2, null, null); 
    items.add(5, 3, null, null); 
    
    var cat1 = items.findByCategory(1);
    alert(cat1); // you will get a result of 3 objects all of which have category 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 89k
  • Answers 90k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In our application we use WF from within an IIS… May 11, 2026 at 5:59 pm
  • Editorial Team
    Editorial Team added an answer As far as I know, mod_rails isn't an alternative. Mongrel… May 11, 2026 at 5:59 pm
  • Editorial Team
    Editorial Team added an answer Well, for one thing you need to somehow generate the… May 11, 2026 at 5:59 pm

Related Questions

I have an outline view delegate and am overriding outlineView:dataCellForTableColumn:item: to make the cells
Is there any built in support in jQuery for basic assertion checking, primarily of
So I have a module in flex in which I add a custom component.
I have these functions: TargetWorksheet.toggle_child_locations = function(id){ $(#location-children-+id).slideToggle(slow); } TargetWorksheet.get_child_locations = function(id, lvl){ //Ajax
I have a code that grabs the buttons click and then vanishes the actual

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.