📜  javascript 对象总数 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:27.095000             🧑  作者: Mango

代码示例1
function sum( obj ) {
  var sum = 0;
  for( var el in obj ) {
    if( obj.hasOwnProperty( el ) ) {
      sum += parseFloat( obj[el] );
    }
  }
  return sum;
}
    
var sample = { a: 1 , b: 2 , c:3 };
var summed = sum( sample );
console.log( "sum: "+summed );