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

  • SEARCH
  • Home
  • 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 7532477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:27:56+00:00 2026-05-30T05:27:56+00:00

I have several images, and I need to be able to group and select

  • 0

I have several images, and I need to be able to group and select them by title, and also manipulate them individually.

My images look like this:

<img src="1.jpg" title="cat">
<img src="2.jpg" title="cat">
<img src="3.jpg" title="cat">
<img src="1.jpg" title="dog">
<img src="2.jpg" title="dog">
<img src="3.jpg" title="dog">
<img src="1.jpg" title="horse">
<img src="2.jpg" title="horse">
<img src="3.jpg" title="horse">

… and so on.

I’m trying to create an array that looks like this:

imgArray = [cat[1,2,3], dog[1,2,3], horse[1,2,3]];

… where the first array level is the group(title), and within each group is an array of the actual elements with matching titles. I need to be able to do things like this:

var imgGroup = imgArray[cat];
doThings(imgGroup)
function doThings(target){
   var pri = target[0], sec = target[1], ter = target[2];
   pri.doThis(); sec.doThat(); ter.doTheotherthing();
});

So far I’m doing this:

img.each(function(){
   var self = $(this),  title = self.attr('title');
   imgArray.push([title, self]) 
   imgArray = $.unique(imgArray) //remove duplicate titles
});

But this is obviously not working and probably for a reason that makes me look stupid :/

Is anyone able to help me with this logic?

  • 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-30T05:27:58+00:00Added an answer on May 30, 2026 at 5:27 am

    I suspect the structure you really need is an object (not an array) where you have a property for each type of animal, and the value of each property is an array of numbers:

    var imgObj = {
       "cat" : [1, 2, 3],
       "dog" : [1, 2, 3],
       "horse" : [1, 2, 3]
    }
    

    Then you can say:

    imgObj["cat"]          // give the array [1,2,3]
    imgObj["horse"].length // gives 3
    imgObj["dog"][0]       // accesses the first value in the dog array
    

    Except that the way your code is trying to create and use your array/object it seems you want the sub arrays to hold jQuery objects that themselves contain the individual DOM img elements? Still you’d want an object where the properties are arrays.

    You didn’t tag your question as jQuery, though from your existing code you seem to be using it, so here’s how you could create the above struture from your markup:

    var imgObj = {};
    $("img").each(function() {
       var title = this.title;
       if (!imgObj.hasOwnProperty(title))
           imgObj[title] = [];
    
       imgObj[title].push($(this));
    });
    

    You should then be able to call your existing doThings() function as follows:

    doThings(imgObj["cat"]);    // passes just the cat array
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several blocks that look like this: <div class='templatechoicedesigncss'> <img src='/images/templatepics/random(100x140).png' /> <p>
I have several images stored in content://media/external/images/media. I would like to display by using
I have several png image files with names like this - house_number_5.png house_number_512.png house_number_52352.png
I have these several images which I need to be combined using BufferedImage in
I have an application which donwloads several images and stores them on the phone.
Need to use own imaged markers instead built-in pins. I have several questions. 1.
I have users that have several objects and can upload images for those objects.
Well, I have dealed quite well with several images onto canvas and now the
I have 2 1024x1024 sprite sheets, one containing several 480x320 background images and another
I have a Tabactivity with several Tabs and the text is overlaying the images

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.