Searching in array



  • Hi guys

    This can be a very basic javascript question for most of you. I just can't figure it out.

    I have an array of product names and their versions like below.

    const var responser = {
        "productVersions": [
        
        { 
            "product_name": "ProductA", 
            "product_version": "1.0.5"  
    
          },
    
         { 
            "product_name": "ProductB", 
            "product_version": "1.2.7"  
    
          },     
          
    
          { 
            "product_name": "ProductC", 
            "product_version": "1.4.2"  
    
          }
          
        ]	 
    };
    

    Let's say I need to take ProductB version number. I can take it with this responser.productVersions[1].product_version

    But How can I take this value with searching the "ProductB" name inside the array and take it's product version (without using a certain array number like above way)?

    Snippet:

    HiseSnippet 1121.3ocsV8taaaCDmxwJaVadXcXO.D9S1XYp1YIsCKnnt1NYyaMoFycAEnnHfQhNhHRjBTzw0KH.64ceZ6In6nnjkrmSfgAhLfrNd+6Gu63cbjT3QSRDRjUs2NOlhr9R6wy4pf9ADFGMb.xpt84TYR+.p20TIp27XRRB0GYYsyOqEwpVUT5y+7xdjPB2iVrDBctf4QeMKhoJVcT2eiEFdBwm9VVTIoOn6POAuuHTLEfyN1sQwDuqIWQOinEqhMxZ2i8YJgbrhnnIHqp8D9yGGHlwMxeNKgcYHUSzAMFLjY4SDg9ZDqWE0OfE5OJeamf.qLpHHriIH7s1mx7YKVuHX70oLvEZTNdXU4gfWmxvq8lCOqRvqpAdOwdrmjEqJ3nw1WXOjqnxIDHETFVFYQU92p18EfDbkaD4Z5IRfXgFMeV616gOrc6VGU2otCjHRT3aHRrN4yD7Arj3PxbpD+BbtUthp5KhhEbfnYiUErg1RE1Is.p2TkRvuWSTRlFFbX9UXEIMADNIEF2V2ACOMhkB+odpL+mz3mvu2vI+cML91LhxJbAGpq.oaLxP+pF6sNotwXWsfcba6dXCL1IWr61SCubs1XO0aC7z9tOeYOgK1Rq6+Mz082.Wef69K4562o52enF7wckxV4+X7PFmhmLk6o.aigy1E4WcAfTD1zKO6uGjeCmRaU2wjWq67zmh+EwLrGgimQwJnjEqBn3LHiyfrQM7LlJ.mPIRu.F+pkDTGAvM0BHlp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u+YsQ+j32lnDgYWSfEFcZZSWCiS4DnJKshD8+vZ58Vh
    


  • @ustk Does the return statment in the loop also stop the loop at that point, like a break statement?



  • @ustk Oh, thank you so much!!!!



  • @d-healey That's exactly what I wondered about, but I never got any issues so...
    A safer method would be to store locally the result, break, and then return... But it's too much to write 🤣



  • @d-healey Apparently yes, but behind the scene, I can't be sure. I imagine this has been taken care of in HiseScript

    HiseSnippet 1112.3ocsVE0SiaDDdcHlV61T06TequrJOEDzHGJbW0gPMWBPUZAtnFJpRUUnE6MjUXuq050bWJJR8eT+e0m5+fqy50N1jKfhhDFgTlc9lY+1YlclcnT3SSRDRjkyESioHquzdzTtZR+IDFGM3HjUC6Koxj9Sn92RkndSiIIIz.jk0F+jFhkScT12+8i8HgDtOsbID5RAymdJKhoJWcX2egEFdBIfdAKpB585NvWv6KBEo.c1v1CES7ukbC8bhFVMaj0lGGvTB4HEQQSPV06IBlNZh38bC9KYIrqCoZgNnQfiLKehHLPyX8pn9SXgACKN1IHvKCKCBaXBBei8Yr.170KCFeclBboEUiGV0dJ50oJ87Vc5YUgd0Mz6E1i7krXUoFM29B6AbEUNl.ofpzxfEU6epa2W.H3p1QjaomHAg4Vz5Udd6f22yaqCZ31vERDIJ7cDIVm7YB9Qrj3PxTpDeHtvK2PU8EQwBNHzp4h.ap8ToexJf5kpTB9i5hJXZZ3g4uRuHoI.3jLZbeCWL70LVJBR8U46eRy2f+iFtNX78XCfpfthC0R.hlCMxus4NKC0cFeoA1osW68aVfY1Nqrq6sBtd21udcbc+Uv060d2RWa9we5.VMKOtx3gLNEONk6q.ivPlHOB1J2eWHNUHt8DgbK26ccBE9jPruHkqfXu2AttNiERbqXLiWlVZuPxXKWGvVG1X.X6pmF7gGh+z8wwwQRUoRNtDc9o5.sR3enxIQDRA0LnjY6syXzVf1YtyV9IC5oTVWoK7jhvV9EUc6.0UgozsZ3lWOYNnKxM3LWlXOHCHjtzmqByyyFKdMncBEprUzOnfjVgKv8JvggjEd6mL5quInyZqvcF8lkeB6SBCuF5e1ZYG+pWtpDmNWnnui2JKe6NyEunpwiWptbmFRkKUstKu7oLrEOM5ZprHST.DZ28v9o1Od+zps68MwoJ.E7Abl5cwT9i0kEkGbge8aCNhnH5Fu4qA3hoRESSAqin2ASzLsgcrOhlbqRDCCmlmQPVelJS6Wk2j1D3Qr.8nzJoBzGlO56uocmVJD0UWsn6xmgFOulAwRNSDA6AQBvspkPtiNfODt7QU5F8nJjvwPhF4j3Tx0zvLN7R6EqPqPjtWVkH2zcLDAFw9qJCoaaVSMUG22DxHgAHCc+V6kUbm0iKCQwfcmMq8u+7G0958r.0jx8V1E8oi5fAtfSCIpGNEV+zibEv97fwc5QZ7DlZZ0ml7rLZdUo6KrGxT9SVNeqsD9BEeO27M+gNMrOd7XJLQYNYqaexu+7+pFzuJRUL9MmQTRFT+YedZzHn7vmBLgyog5q6V0zWLMxdZYcjYDkGjI7Q3KWYGsrUtxNEJQQDeo3JeSSF8So97rU.NwydQoi8YZYbGTViGvNau1dnH3EdW46qCEeGv8kaytqgMe+ZXydqgM6uF17p0vlWuF17COoM5GW+1TkHxbMAVX3wYcisrNlSfprrJRz+CfseE9E
    


  • @ustk Looks good to me, I'll use it 🙂





  • @ustk Excellent, the joys of source code 🙂


Log in to reply
 

11
Online

1.5k
Users

4.6k
Topics

42.1k
Posts