2

There are 3 array ,in this value I have to take count of _activityStatus :"I" (ony I value) . one way i am trying is

    StepsStatus :[]

    StepsStatus = StepsVaue.map(StepsVaue => {
          return StepsVaue._activityStatus;
    }); 

I am taking all _activityStatus in StepsStatus . Now I have to take count of I value only .

currentNextActivity: Array(3)
    0:
    __typename: "CurrentNextActivity"
    _activityName: "FXL_ACT1"
    _activityStatus: "I"
    _maxHoldTime: "60"
    _userName: "tecnotree"

   1:
    __typename: "CurrentNextActivity"
    _activityName: "FXL_ACT2"
    _activityStatus: "I"
    _maxHoldTime: "60"
    _userName: "tecnotree"
    __proto__: Object

    2:
    __typename: "CurrentNextActivity"
    _activityName: "FXL_ACT3"
    _activityStatus: "N"
    _maxHoldTime: "120"
    _userName: null

Thanks

2 Answers 2

7

You can use array.filter() to create a new array, using only items that match a certain condition.

let iValues = StepsVaue.filter((item) => {
   return item._activityStatus === "I"
})

console.log(iValues.length)

You may also use array.reduce() as Diamond suggested, just remember to define a default value or your result may not be what you expect. :)

StepsVaue.reduce((total, item) => total + (item._activityStatus === "I" ? 1 : 0), 0)
Sign up to request clarification or add additional context in comments.

1 Comment

could you please help me for this stackoverflow.com/questions/56424607/…
5

You can use filter() function to filter items.

StepsValue.filter(item => item._activityStatus === "I").length

Or you can use reduce() function

StepsValue.reduce((count, item) => count + (item._activityStatus === "I" ? 1 : 0), 0)

I prefer to use reduce() because it will use less memory than filter().

Good Luck.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.