Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Help with JavaScript array!

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #149164
    Manuel87
    Participant

    Hi all,

    I am new to JavaScript i am trying to accomplish something relatively simple but it’s hard for me please someone give me a hint.

    I have an array of images, i need to take that array and compare the attr.alt of the image to a list that i have if they are the same then i need to assign the attr.src of that image to a variable .

    Here is what i have but it’s not working.

    var imagesArray = $('#product-photo-thumbs img');
    
    if ( properties.variant.title == imagesArray.attr('alt')){
        return $(this).attr('src');
    }
    
    #149165
    TheDoc
    Member

    Well, for starts imagesArray isn’t an array, it’s a jQuery collection (an object).

    If you’re using jQuery you could do something like this:

    imagesArray.each( function () {
        if( properties.variant.title == $(this).attr('alt') ) {
            // do something
        }
    });
    
    #149281
    Manuel87
    Participant

    Hi,

    thank you very much for your help you saved me a lot of time.

    I am currently trying to learn JavaScript could you recommend me any book or online course, i will really appreciate your recommendation.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.