-2

I want to find the sum of the length of all paths for an svg paths. And I have the following( the paths are put in an array):

...
    var totalPxl=0;
      for (var i=0; i < this.pathArray.length; i++){
        var totalPxl = this.pathArray[i].getTotalLength();

        console.log(totalPxl);
      }

This lists all the paths length individually, How can I add them up?

Any ideas would be appreciated

Bayan
  • 27
  • 1
  • 8

1 Answers1

0

Replace var totalPxl = this.pathArray[i].getTotalLength(); by

totalPxl += this.pathArray[i].getTotalLength();

If you just want to print the total, move the console.log statement outside and below the for loop.

Robert Longson
  • 118,664
  • 26
  • 252
  • 242
  • Thank you very much @Robert. That works perfect. it lists all the paths added to the previous one. How can I get only the last number which is the sum of all the paths? – Bayan Dec 05 '14 at 08:45