Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8285567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:30:12+00:00 2026-06-08T11:30:12+00:00

I want to push all 0.0 value in object, so I can count how

  • 0

I want to push all 0.0 value in object, so I can count how many 0.0 value in an object. So far I’ve made a code to push all values (including 0.0) but now I just want to push ONLY 0.0 VALUE.
for example:
in ['cm_per1'] there is 2 “0.0”, then I want to push them as final_results['ESL']['cm_per1'] and when I call final_results['ESL']['cm_per1'].length, it will show “2” (because there is 2 “0.0” in cm_per1)

here is what I’ve made so far >> http://jsfiddle.net/xKJn8/26/

var data = {
  "MyData": [
    {
      "cm_per1": "21.9",
      "cm_per2": "31.8",
      "tipe": "ESL"
    },
    {      
      "cm_per1": "8.6",
      "cm_per2": "7.0",
      "tipe": "ESL"
    },
    {      
      "cm_per1": "3.2",
      "cm_per2": "0.0",
      "tipe": "ESL"
    },
    {
      "cm_per1": "0.0",
      "cm_per2": "0.0",
      "tipe": "ESL"
    },
    {
      "cm_per1": "0.0",
      "cm_per2": "0.0",
      "tipe": "ESL"
    }
  ]
};

var final_results = {},
    type,
    current_row= "";
for (var i=0; i<data.MyData.length; i++) {
    current_row = data.MyData[i];
    type = current_row.tipe;

    //I want to count how many cm_per1 and cm_per2 that have 0.0 value    
    if (!final_results[type]) {
            final_results[type] = {
                  "cm_per1": [],
                  "cm_per2": []  
            };
    }

    final_results[type].cm_per2.push(current_row.cm_per2);
    final_results[type].cm_per1.push(current_row.cm_per1);
}
//but the result is it counts all cm_per1 and cm_per2, and what I need is only counts that have 0.0 value
console.log(final_results['ESL']['cm_per1'].length);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:30:14+00:00Added an answer on June 8, 2026 at 11:30 am
    var final_results = {};
    
    data.MyData.forEach( function( o ) {
        // First check if it doesn't exist :-)
        if (!final_results[ o.tipe ]) {
            final_results[ o.tipe ] = {
                "cm_per1": [],
                "cm_per2": []  
            };
        }
    
        // Only push if the value is '0.0'
        if ( o.cm_per1 === '0.0' ) {
            final_results[ o.tipe ][ 'cm_per1' ].push( o.cm_per1 );
        }
        if ( o.cm_per2 === '0.0' ) {
            final_results[ o.tipe ][ 'cm_per2' ].push( o.cm_per2 );
        }
    });
    console.log( final_results[ 'ESL' ][ 'cm_per1' ].length ); // 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to push many objects into a array and each object have different
I want to see a list of all changes the next push would do.
Right now, I have a list of streams, and I want to push streams
Code is working fine but i want to add my own location . for
I'm trying to track all changes made to a PHP variable. The variable can
I want to copy all attributes from backbone.js Model object to another if they
I want to push a file from my Java program to an Android emulator.
Generally whenever i want to push in the changes to remote Git i follow
I have a project that I want to push to a Mercurial repository on
Read about Server push here . I want to push data to client from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.