The length of the notification is determined by the ReadFlag

JS:

 function fetchNotifications(){
                $.ajax({
                    url: "getgroupednotification.json",
                    type: "GET",
                    crossDomain: true,
                    success:function(response){

                        $.each(response,function(idx, val){
                            //console.log(response);
                            //console.log(val);
                            $.each(val.Notifications, function(idx_, val_){
                                if(val.Source == 'CIRIS'){
                                    var totalNotifications = val.Notifications.length;
                                        if(val_.ReadFlag != 1){

                                    }
                                }
                            });
                       });
                 });

I am trying to retrieve the count of notifications where ReadFlag is equal to 0. In this example scenario, I am checking for Source being CIRIS.

You can access my JSON data from this link:

Answer №1

One possible solution could be:

function fetchJSONData() {
    $.ajax({
        url: "https://api.myjson.com/bins/navph",
        type: "GET",
        crossDomain: true,
        success: function(response) {
            var notificationLengths = response.filter(function(item) {
                return item.Source === 'CIRIS';
            }).map(function(item) {
                return item.Notifications;
            }).map(function(notification){
                return (notification.filter(function(item){
                    return item.RedFlag !== 0;
                }).length)
            })
            console.log(notificationLengths[0]);
        }
    })
}

fetchJSONData();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Embed fashion and graph elements into a CSV document (generated from <script>)

Encountering an issue with my code. I am looking to export an HTML table to a CSV file (specifically Libre Office Calc, regardless of csv, xls or xlsx format, as long as it runs on a Linux Server). Found a script online that works well after some modificat ...

The process of assigning a local variable to a JSON response in Angular 2

I need to store a JSON response that includes an array with the following data: 0 : {ID: 2, NAME: "asd", PWD_EXPIRY_IN_DAYS: 30} 1 : {ID: 1, NAME: "Admin", PWD_EXPIRY_IN_DAYS: 30} In my code, I have defined a local variable called groups of type ...

The fade effect in React and material ui is consistent across both elements

I am facing an issue with a list where, for each list sibling onclick, a different element fades in with different text. The problem occurs when the fade effect starts once on siblings in the list and then disappears, not enabling again. This is the code: ...

The previous state is retained by useState, rather than updating to the current value

Hello, I'm currently learning about React and its functionality. My project involves having 2 select inputs that should update based on each other's value changes. However, I've noticed that after using setOptions to update the filtered va ...

What is the best method for automatically closing the modal window?

I implemented a modal window on my website. Within the modal, there is a green button labeled "Visit" which triggers the "Bootstrap Tour". I aim for the modal to automatically close when the tour starts. To access this feature on my site, users need to ...

Sequence jQuery functions so that each one only runs when the previous one has finished

I want to have more control over the order of my functions in jQuery. When I click on an element, I would like an image to fade out, change its source, and then fade in the new image. The code I currently have kind of works, but it performs all these acti ...

Using C# and JSON.net to iterate and save Jobject objects in a loop

Recently started learning C# and exploring JSON. I am attempting to work with JSON data from a web API in a specific format. My goal is to iterate through the data, extract the secondUser_id and status values, and store them for future use. { "user_list ...

utilizing a spacemouse in conjunction with autodesk forge

Recently, I acquired a 3dconnexion spacemouse and have been attempting to configure it to work with the forge viewer. Fortunately, I came across some JS samples in the SDK for three.js that worked flawlessly. It seems both forge and three.js utilize webgl ...

Combine two elements together and display the outcome in json form

There are two objects that need to be summed up and returned in the same format as the original objects stored in a local file. The first JSON: { "data": [{ "x": "Q1 (J, F, M)", "y": [100, 500, 0], "tooltip": "this is tooltip" }, { "x": "Q2(A, M, ...

Is there a way to automatically adjust the positioning of added pins on an image as I scroll through the image?

I have inserted a large image onto my HTML page and to manage its size, I am displaying it within a div that allows for scrolling like a map. Using jQuery, I have placed 3 markers on the image. The issue I am facing is that when I scroll the image, the ma ...

Ways to delete an element from an array in MongoDB

I am a beginner in the MEAN stack development. I am currently working on implementing this and this. I have been using the $pull method, but it seems that it is not working for me. I suspect that the issue might be due to the differences in my MongoDB stru ...

What is the method for obtaining an element with a class name that does not match a specific value?

I'm trying to figure out how to select an element with a class name that is different from the value passed in. For example: $(document).ready(function () { $(document).on('change', '#allRolesDD', function () { var toS ...

I'm encountering an issue with my array in JavaScript while using // @ts-check in VS Code. Why am I receiving an error stating that property 'find' does not exist on my array? (typescript 2.7

** update console.log(Array.isArray(primaryNumberFemales)); // true and I export it with: export { primaryNumberFemales, }; ** end update I possess an array (which is indeed a type of object) that is structured in the following manner: const primar ...

Issue with Type-Error when accessing theme using StyledComponents and TypeScript in Material-UI(React)

I attempted to access the theme within one of my styled components like this: const ToolbarPlaceholder = styled('div')((theme: any) => ({ minHeight: theme.mixins.toolbar.minHeight, })); This information was found in the documentation: htt ...

"Adding page-specific scripts with the help of nunjucks and express app: A step-by-step guide

What is the most efficient way to manage scripts that are common for all pages and scripts that are specific to certain pages using nunjucks as the template engine and express 4 as the backend framework? --- site --- public |___js |___ script.js (f ...

Modify the content of package.json using command line interface

I need to modify a variable within my package.json file using a shell script. For example, if my package.json looks like this: { "name": "my-project", "description": "Project by @DerZyklop", "version": "0.0.0", ... I want to use the following com ...

Ruby application requires refreshing for Ajax deletions to take effect

I am currently working on developing a task management app using Rails. Each to-do list in the app contains multiple tasks, and my issue lies in deleting a completed task with Ajax without having to manually refresh the page for it to vanish. As I am still ...

Tips for customizing the cursor to avoid it reverting to the conventional scroll cursor when using the middle click

When you wish to navigate by scrolling with the middle mouse button instead of using the scroll wheel, simply middle-click and your cursor will change allowing for easy scrolling on web pages. Even though I am utilizing style="cursor: pointer" and @click. ...

Generate numerous div elements by utilizing ng-repeat

I am trying to generate 'n' red blocks with text (where n represents the number of elements in an array), but unfortunately, I am seeing a blank page. <html> <body> <script src="https://ajax.googleapis.com/ajax/libs/angu ...

Using JSON data in a Java servlet can be done by first creating a JSON

I am working with knockout js and need to send json data to my servlet. I am having trouble extracting the value of a key from the json data. Here is an example of my json data: {"data":[{"BranchId":"xzc","Name":"zxc","Description":"zxc","Template":"Templ ...