Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
63
rated 0 times [  64] [ 1]  / answers: 1 / hits: 6813  / 4 Years ago, tue, may 12, 2020, 12:00:00

I have to check if any of the cuesData has a value or length greater than 0.
In my code below, i can only check the first array but not the others.



enter



TS



checkValues(values) {
const result = Object.values(values).every((value) => value[1].cuesData.length > 0);
return result;
}


HTML



<div *ngIf=checkValues(values) === true>


JSON



  [
[
videoData__1,
{
id: 1,
title: Pale Blue Dot,
stoppedAt: 97.834667,
cuesData: [
{
startTime: 25.335678,
endTime: 35.335678,
description: fqff
}
]
}
],
[
videoData__2,
{
id: 2,
title: Big Buck Bunny,
stoppedAt: 247.57881,
cuesData: []
}
],
[
videoData__3,
{
id: 3,
title: Elephants Dream,
stoppedAt: 404.585327,
cuesData: []
}
]
]

More From » arrays

 Answers
3

Change,



checkValues(values) {
const result = Object.values(values).every((value) => value[1].cuesData.length > 0);
return result;
}


To



checkValues(values){
const result = Object.values(values).some((value) => value[1].cuesData.length > 0);
return result;
}



Working Stackblitz: https://stackblitz.com/edit/my-angular-starter-j4yypu




Here .every() method will check that all conditions should met but whereas some() method works that at least one condition has been true..



Stackblitz without cuesdata length: https://stackblitz.com/edit/my-angular-starter-cfpxa5


[#3846] Friday, May 8, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jarettajb

Total Points: 678
Total Questions: 94
Total Answers: 90

Location: Guernsey
Member since Tue, Jul 6, 2021
3 Years ago
;