Skip to content Skip to sidebar Skip to footer

How To Call Items From An Array Inside A Function

I have a function 'zoom' which takes the following format: zoom( [a,b,c,d....], [a,b,c,d...] ); I also have a for loop which gets me the values that need to go into the zoom array

Solution 1:

You cannot execute the call to ABC.zoom() inside the .forEach() loop, since you'll only get the whole data set once all iterations have been executed.

I think you need something along those lines:

var zoomA = [],
    zoomB = [];

ABC.getAggregation("V")[0].getItems().forEach( function (item) {
  var a = item.getPosition().split(";")[0];
  var b = item.getPosition().split(";")[1];
  zoomA.push(Number(a));
  zoomB.push(Number(b));
});

ABC.zoom(zoomA, zoomB);

Please let me know if I somehow misunderstood what you are trying to do.

Solution 2:

Split return an array of strings, so item.getPosition().split(";")[0]; will return a string, not three strings. You need to split it again with , delimiter, parse the result array to int (you can use map function) and pass to zoom function.

Post a Comment for "How To Call Items From An Array Inside A Function"