Skip to main content

data

 const jsonData = [

    {

        "id": 16,

        "city": "Segaon Tahsil",

        "city_status": "A",

        "area": []

    },

    {

        "id": 15,

        "city": "Hyderabad",

        "city_status": "A",

        "area": [

            {

                "id": 3,

                "highlighted_area": "Ameerpet-Hyderabad",

                "location": 15

            },

            {

                "id": 4,

                "highlighted_area": "Begumpet-Hyderabad",

                "location": 15

            },

            {

                "id": 6,

                "highlighted_area": "Khairatabad-Hyderabad",

                "location": 15

            },

            {

                "id": 7,

                "highlighted_area": "Punjagutta-Hyderabad",

                "location": 15

            }

        ]

    }

];


function extractLocations(data) {

    const locations = [];


    data.forEach(item => {

        if (item.city) {

            // Add city itself as a location

            locations.push({ location: item.city });

            // Add all highlighted areas if available

            item.area.forEach(areaItem => {

                if (areaItem.highlighted_area) {

                    locations.push({ location: areaItem.highlighted_area });

                }

            });

        }

    });


    return locations;

}


const locationData = extractLocations(jsonData);

console.log(locationData);


Comments

Popular posts from this blog

Log time Cookis asp.net

  HttpCookie Cookie = new HttpCookie("Client");                 Cookie["ID"] = ds.Tables[0].Rows[0]["UserName"].ToString(); ;                 Cookie.Expires=DateTime.Now.AddYears(2);                 Response.Cookies.Add(Cookie);

Asp.webconfig Api Delete post put get all allwo

 <?xml version="1.0" encoding="utf-8"?> <!--   For more information on how to configure your ASP.NET application, please visit   http://go.microsoft.com/fwlink/?LinkId=301879   --> <configuration>   <configSections>        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->   <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />   </configSections>   <connectionStrings>     <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-chatapi-20230925125315.mdf;Initial Catalog=aspnet-chatapi-20230925125315;Integrated Security=True" providerName="System.Data.SqlClient" />   ...