How to check whether a boolean value is false in every object of an array in?












0















I have an array which consists of multiple objects:



quesListArray = [
{Position: 1, Mandatory: false},
{Position: 2, Mandatory: true},
{Position: 3, Mandatory: false},
...
...
]


How can I get to know whether 'Mandatory' field in every object is false or not. If all are false then I need to show a message.



Any help will be appreciated. Thank you.










share|improve this question




















  • 1





    how is this question related to Angular?

    – JulianG
    Dec 30 '18 at 19:52
















0















I have an array which consists of multiple objects:



quesListArray = [
{Position: 1, Mandatory: false},
{Position: 2, Mandatory: true},
{Position: 3, Mandatory: false},
...
...
]


How can I get to know whether 'Mandatory' field in every object is false or not. If all are false then I need to show a message.



Any help will be appreciated. Thank you.










share|improve this question




















  • 1





    how is this question related to Angular?

    – JulianG
    Dec 30 '18 at 19:52














0












0








0








I have an array which consists of multiple objects:



quesListArray = [
{Position: 1, Mandatory: false},
{Position: 2, Mandatory: true},
{Position: 3, Mandatory: false},
...
...
]


How can I get to know whether 'Mandatory' field in every object is false or not. If all are false then I need to show a message.



Any help will be appreciated. Thank you.










share|improve this question
















I have an array which consists of multiple objects:



quesListArray = [
{Position: 1, Mandatory: false},
{Position: 2, Mandatory: true},
{Position: 3, Mandatory: false},
...
...
]


How can I get to know whether 'Mandatory' field in every object is false or not. If all are false then I need to show a message.



Any help will be appreciated. Thank you.







typescript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 31 '18 at 5:42









Ingo Bürk

10.8k53575




10.8k53575










asked Dec 30 '18 at 5:01









Mr. AMr. A

53




53








  • 1





    how is this question related to Angular?

    – JulianG
    Dec 30 '18 at 19:52














  • 1





    how is this question related to Angular?

    – JulianG
    Dec 30 '18 at 19:52








1




1





how is this question related to Angular?

– JulianG
Dec 30 '18 at 19:52





how is this question related to Angular?

– JulianG
Dec 30 '18 at 19:52












3 Answers
3






active

oldest

votes


















2














Use every with arrow function (for brevity) on questListArray, like so:



areAllMandatoriesFalse() {
if (this.quesListArray.every(item => !item.Mandatory)) {
alert("All are false");
}
else {
alert("Not all are false");
}
}


DEMO






share|improve this answer


























  • @Mr.A: please do practise to upvote the answer if helpfull and mark as accepted if answer is perfect.

    – baj9032
    Dec 30 '18 at 6:01



















1














use 'every'.
for example:



function isBelowThreshold(currentValue) {
return currentValue < 40;
}

var array = [1, 30, 39, 29, 10, 13];

console.log(array.every(isBelowThreshold));
// expected output: true


I hope my help is effective ツ






share|improve this answer
























  • I already suggested using "every". In less than 4 min two upvotes are suspisious

    – Vega
    Dec 30 '18 at 7:18













  • I got into this problem today at the company. I answered this answer and two of my colleagues liked it... :) @Vega

    – user10780188
    Dec 30 '18 at 7:26





















0














Try this:



checkPropAreFalse() {
let MandatoryFlag = true;
for (let index = 0; index < this.quesListArray.length; index++) {
const element = this.quesListArray[index];
if (!element.Mandatory) {
continue;
} else {
MandatoryFlag = false;
break;
}
}
return MandatoryFlag;
}


Call Method from your file:



const responce = this.checkPropAreFalse();





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53975385%2fhow-to-check-whether-a-boolean-value-is-false-in-every-object-of-an-array-in%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Use every with arrow function (for brevity) on questListArray, like so:



    areAllMandatoriesFalse() {
    if (this.quesListArray.every(item => !item.Mandatory)) {
    alert("All are false");
    }
    else {
    alert("Not all are false");
    }
    }


    DEMO






    share|improve this answer


























    • @Mr.A: please do practise to upvote the answer if helpfull and mark as accepted if answer is perfect.

      – baj9032
      Dec 30 '18 at 6:01
















    2














    Use every with arrow function (for brevity) on questListArray, like so:



    areAllMandatoriesFalse() {
    if (this.quesListArray.every(item => !item.Mandatory)) {
    alert("All are false");
    }
    else {
    alert("Not all are false");
    }
    }


    DEMO






    share|improve this answer


























    • @Mr.A: please do practise to upvote the answer if helpfull and mark as accepted if answer is perfect.

      – baj9032
      Dec 30 '18 at 6:01














    2












    2








    2







    Use every with arrow function (for brevity) on questListArray, like so:



    areAllMandatoriesFalse() {
    if (this.quesListArray.every(item => !item.Mandatory)) {
    alert("All are false");
    }
    else {
    alert("Not all are false");
    }
    }


    DEMO






    share|improve this answer















    Use every with arrow function (for brevity) on questListArray, like so:



    areAllMandatoriesFalse() {
    if (this.quesListArray.every(item => !item.Mandatory)) {
    alert("All are false");
    }
    else {
    alert("Not all are false");
    }
    }


    DEMO







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 31 '18 at 5:40

























    answered Dec 30 '18 at 5:19









    VegaVega

    12.8k113655




    12.8k113655













    • @Mr.A: please do practise to upvote the answer if helpfull and mark as accepted if answer is perfect.

      – baj9032
      Dec 30 '18 at 6:01



















    • @Mr.A: please do practise to upvote the answer if helpfull and mark as accepted if answer is perfect.

      – baj9032
      Dec 30 '18 at 6:01

















    @Mr.A: please do practise to upvote the answer if helpfull and mark as accepted if answer is perfect.

    – baj9032
    Dec 30 '18 at 6:01





    @Mr.A: please do practise to upvote the answer if helpfull and mark as accepted if answer is perfect.

    – baj9032
    Dec 30 '18 at 6:01













    1














    use 'every'.
    for example:



    function isBelowThreshold(currentValue) {
    return currentValue < 40;
    }

    var array = [1, 30, 39, 29, 10, 13];

    console.log(array.every(isBelowThreshold));
    // expected output: true


    I hope my help is effective ツ






    share|improve this answer
























    • I already suggested using "every". In less than 4 min two upvotes are suspisious

      – Vega
      Dec 30 '18 at 7:18













    • I got into this problem today at the company. I answered this answer and two of my colleagues liked it... :) @Vega

      – user10780188
      Dec 30 '18 at 7:26


















    1














    use 'every'.
    for example:



    function isBelowThreshold(currentValue) {
    return currentValue < 40;
    }

    var array = [1, 30, 39, 29, 10, 13];

    console.log(array.every(isBelowThreshold));
    // expected output: true


    I hope my help is effective ツ






    share|improve this answer
























    • I already suggested using "every". In less than 4 min two upvotes are suspisious

      – Vega
      Dec 30 '18 at 7:18













    • I got into this problem today at the company. I answered this answer and two of my colleagues liked it... :) @Vega

      – user10780188
      Dec 30 '18 at 7:26
















    1












    1








    1







    use 'every'.
    for example:



    function isBelowThreshold(currentValue) {
    return currentValue < 40;
    }

    var array = [1, 30, 39, 29, 10, 13];

    console.log(array.every(isBelowThreshold));
    // expected output: true


    I hope my help is effective ツ






    share|improve this answer













    use 'every'.
    for example:



    function isBelowThreshold(currentValue) {
    return currentValue < 40;
    }

    var array = [1, 30, 39, 29, 10, 13];

    console.log(array.every(isBelowThreshold));
    // expected output: true


    I hope my help is effective ツ







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Dec 30 '18 at 7:13







    user10780188




















    • I already suggested using "every". In less than 4 min two upvotes are suspisious

      – Vega
      Dec 30 '18 at 7:18













    • I got into this problem today at the company. I answered this answer and two of my colleagues liked it... :) @Vega

      – user10780188
      Dec 30 '18 at 7:26





















    • I already suggested using "every". In less than 4 min two upvotes are suspisious

      – Vega
      Dec 30 '18 at 7:18













    • I got into this problem today at the company. I answered this answer and two of my colleagues liked it... :) @Vega

      – user10780188
      Dec 30 '18 at 7:26



















    I already suggested using "every". In less than 4 min two upvotes are suspisious

    – Vega
    Dec 30 '18 at 7:18







    I already suggested using "every". In less than 4 min two upvotes are suspisious

    – Vega
    Dec 30 '18 at 7:18















    I got into this problem today at the company. I answered this answer and two of my colleagues liked it... :) @Vega

    – user10780188
    Dec 30 '18 at 7:26







    I got into this problem today at the company. I answered this answer and two of my colleagues liked it... :) @Vega

    – user10780188
    Dec 30 '18 at 7:26













    0














    Try this:



    checkPropAreFalse() {
    let MandatoryFlag = true;
    for (let index = 0; index < this.quesListArray.length; index++) {
    const element = this.quesListArray[index];
    if (!element.Mandatory) {
    continue;
    } else {
    MandatoryFlag = false;
    break;
    }
    }
    return MandatoryFlag;
    }


    Call Method from your file:



    const responce = this.checkPropAreFalse();





    share|improve this answer




























      0














      Try this:



      checkPropAreFalse() {
      let MandatoryFlag = true;
      for (let index = 0; index < this.quesListArray.length; index++) {
      const element = this.quesListArray[index];
      if (!element.Mandatory) {
      continue;
      } else {
      MandatoryFlag = false;
      break;
      }
      }
      return MandatoryFlag;
      }


      Call Method from your file:



      const responce = this.checkPropAreFalse();





      share|improve this answer


























        0












        0








        0







        Try this:



        checkPropAreFalse() {
        let MandatoryFlag = true;
        for (let index = 0; index < this.quesListArray.length; index++) {
        const element = this.quesListArray[index];
        if (!element.Mandatory) {
        continue;
        } else {
        MandatoryFlag = false;
        break;
        }
        }
        return MandatoryFlag;
        }


        Call Method from your file:



        const responce = this.checkPropAreFalse();





        share|improve this answer













        Try this:



        checkPropAreFalse() {
        let MandatoryFlag = true;
        for (let index = 0; index < this.quesListArray.length; index++) {
        const element = this.quesListArray[index];
        if (!element.Mandatory) {
        continue;
        } else {
        MandatoryFlag = false;
        break;
        }
        }
        return MandatoryFlag;
        }


        Call Method from your file:



        const responce = this.checkPropAreFalse();






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 30 '18 at 5:29









        baj9032baj9032

        1,0351827




        1,0351827






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53975385%2fhow-to-check-whether-a-boolean-value-is-false-in-every-object-of-an-array-in%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas