<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[arrays සම්බන්ද, මේ JavaScript ගැටලුව විසද ගන්න උදව් ඕන.]]></title><description><![CDATA[<p dir="auto">මම API එකකින් response එක ගන්නවා. එකේන්, මේ පහල විධියට arrays 2ක් එක්ක response එක එනව.</p>
<pre><code>routesOutput: [{origin_iata: "CMB", destination_iata: "IST",…}, {origin_iata: "CMB", destination_iata: "SAW",…}]
    0: {origin_iata: "CMB", destination_iata: "IST",…}
    1: {origin_iata: "CMB", destination_iata: "SAW",…}
schedulesOutput: [{departure_iata: "CMB", arrival_iata: "MLE",…}, {departure_iata: "MLE", arrival_iata: "IST",…},…]
    0: {departure_iata: "CMB", arrival_iata: "MLE",…}
    1: {departure_iata: "MLE", arrival_iata: "IST",…}
</code></pre>
<p dir="auto">මේකේ, routesOutput කියන array එක ඇතුලේ weekly කියල තව array එකක් තියෙනව. ඒක ඇතුලේ flight_ids කියල එකක් තියෙනව. මේ පහල විධියට.</p>
<ul>
<li>routesOutput[0].schedules.weekly[0].flights.flight_ids</li>
</ul>
<pre><code>routesOutput: [{origin_iata: "CMB", destination_iata: "IST",…}, {origin_iata: "CMB", destination_iata: "SAW",…}]
    schedules: {updated: {}, weekly: [{routing_id: "159058258847310869390999", frquency: [1, 1, 0, 1, 1, 0, 1],…},…]}
        weekly: [{routing_id: "159058258847310869390999", frquency: [1, 1, 0, 1, 1, 0, 1],…},…]
            0: {routing_id: "159058258847310869390999", frquency: [1, 1, 0, 1, 1, 0, 1],…}
                technical_stops: "MLE"
                    flights: {flight_ids: ["159058258847310869501898", "159058258847310869627899"]}
                        flight_ids: ["159058258847310869501898", "159058258847310869627899"]
                            0: "159058258847310869501898"
                            1: "159058258847310869627899"
</code></pre>
<p dir="auto">ඒ වගේම, schedulesOutput කියන array එක ඇතුලේත් flight_ids කියල තියේනව. මේ පහල විධියටම.</p>
<ul>
<li>schedulesOutput[0].flights.flight_ids</li>
</ul>
<pre><code>schedulesOutput: [{departure_iata: "CMB", arrival_iata: "MLE",…}, {departure_iata: "MLE", arrival_iata: "IST",…},…]
    0: {departure_iata: "CMB", arrival_iata: "MLE",…}
        flights: [{flight_ids: "159058258847310869501898", operating_iata: "TK",…},…]
            0: {flight_ids "159058258847310869501898", operating_iata: "TK",…}
                flight_ids: "159058258847310869501898":
</code></pre>
<p dir="auto">මම for loops පාවිච්චි කරල , ඒවා loop කරල, arrays 2ම එක සමාන flight_ids තියේන ඒවා අරගෙන, ඒවා එක array එකකට push කරා. නමුත්, routesOutput[0].schedules.weekly[0].flights.flight_ids[0] හා [1] එකම element එකකට push කරන්න තමයි මට ඕන.</p>
<p dir="auto">මෙහම තමයි මට ලැබුනේ.</p>
<pre><code>[
  {
    "ori_sub_origin": "CMB",
    "ori_sub_desti": "MLE"
  },
   {
    "desti_sub_origin": "MLE",
    "desti_sub_desti": "IST"
  },
 ]
</code></pre>
<p dir="auto">මේ විධියටයි මට ඕන වෙන්නේ.</p>
<pre><code> [
  {
    "ori_sub_origin": "CMB",
    "ori_sub_desti": "MLE",
    "desti_sub_origin": "MLE",
    "desti_sub_desti": "IST"
  }
 ]
</code></pre>
<p dir="auto">මෙන්න මගේ කෝඩ් එක.</p>
<pre><code>for(i = 0; i &lt; routes_with_weekly.length; i++) {
       let test_one = routes_with_weekly[i].flights.flight_ids[0];
       let test_one_desti = routes_with_weekly[i].flights.flight_ids[1];
       for(j = 0; j &lt; schedulesOutput_let.length; j++) {
           if(schedulesOutput_let[j].flights[j] != undefined) {
               let test_two = schedulesOutput_let[j].flights;
               for(v = 0; v &lt; test_two.length; v++) {
                   let test_three = test_two[v].flight_ids;
                   if(test_one == test_three) {
                       let ori_all_data = {
                           "ori_sub_origin" : schedulesOutput_let[j].departure_iata,
                           "ori_sub_desti" : schedulesOutput_let[j].arrival_iata
                       };
                       all_data_arr.push(ori_all_data);
                       // break;
                   }
               }
           }
       }
   }

   //desti
   for(r = 0; r &lt; routes_with_weekly.length; r++) {
       let test_one = routes_with_weekly[r].flights.flight_ids[1];
       for(t = 0; t &lt; schedulesOutput_let.length; t++) {
           if(schedulesOutput_let[t].flights[t] != undefined) {
               let test_two = schedulesOutput_let[t].flights;
               for(b = 0; b &lt; test_two.length; b++) {
                   let test_three = test_two[b].flight_ids;
                   if(test_one == test_three) {
                           let desti_all_data = { 
                               "desti_sub_origin" : schedulesOutput_let[t].departure_iata,
                               "desti_sub_desti" : schedulesOutput_let[t].arrival_iata
                           };
                           all_data_arr.push(desti_all_data);
                           // break;                    }
               }
           }
       }
   } 
   console.log(JSON.stringify(all_data_arr , null, 2))
</code></pre>
]]></description><link>https://lankadevelopers.lk/topic/587/arrays-සම-බන-ද-ම-javascript-ග-ටල-ව-ව-සද-ගන-න-උදව-ඕන</link><generator>RSS for Node</generator><lastBuildDate>Tue, 09 Jun 2026 02:45:59 GMT</lastBuildDate><atom:link href="https://lankadevelopers.lk/topic/587.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 28 May 2020 12:52:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to arrays සම්බන්ද, මේ JavaScript ගැටලුව විසද ගන්න උදව් ඕන. on Wed, 22 Jul 2020 04:31:15 GMT]]></title><description><![CDATA[<p dir="auto">meken idea ekak ganna puluwan wei <a href="https://stackoverflow.com/questions/62949257/how-to-access-an-array-in-an-array-in-a-collection" target="_blank" rel="noopener noreferrer nofollow ugc">https://stackoverflow.com/questions/62949257/how-to-access-an-array-in-an-array-in-a-collection</a></p>
]]></description><link>https://lankadevelopers.lk/post/3686</link><guid isPermaLink="true">https://lankadevelopers.lk/post/3686</guid><dc:creator><![CDATA[ijseGovindu]]></dc:creator><pubDate>Wed, 22 Jul 2020 04:31:15 GMT</pubDate></item><item><title><![CDATA[Reply to arrays සම්බන්ද, මේ JavaScript ගැටලුව විසද ගන්න උදව් ඕන. on Thu, 16 Jul 2020 23:40:09 GMT]]></title><description><![CDATA[<p dir="auto">Object Assign method eka use karanna<br />
karanna</p>
]]></description><link>https://lankadevelopers.lk/post/3638</link><guid isPermaLink="true">https://lankadevelopers.lk/post/3638</guid><dc:creator><![CDATA[Harshana Saparamadu]]></dc:creator><pubDate>Thu, 16 Jul 2020 23:40:09 GMT</pubDate></item></channel></rss>