How to check whether a boolean value is false in every object of an array in?
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
add a comment |
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
1
how is this question related to Angular?
– JulianG
Dec 30 '18 at 19:52
add a comment |
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
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
typescript
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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
@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
add a comment |
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 ツ
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
add a comment |
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();
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
@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
add a comment |
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
@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
add a comment |
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
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
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
add a comment |
@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
add a comment |
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 ツ
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
add a comment |
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 ツ
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
add a comment |
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 ツ
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 ツ
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
add a comment |
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
add a comment |
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();
add a comment |
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();
add a comment |
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();
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();
answered Dec 30 '18 at 5:29
baj9032baj9032
1,0351827
1,0351827
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
how is this question related to Angular?
– JulianG
Dec 30 '18 at 19:52