2

Here I have a nArray function which return me a bigArray - JSON so with nArray function I create a bigArray objects

Example:

Array[5]
0: Object
1: Object
     DISTANCE_FROM_PREVIOUS_OBJECT_LOCATION: 2.087970147789207
     lat: "48.866588"
     leftPosition: 183
     lng: "2.309037999999987"
     topPosition: 57
        __proto__: Object
2: Object
3: Object
4: Object
length: 5
__proto__: Array[0]

As you can see I have Objetcs in bigArray that contain: lat,left,lng,top and DISTANCE_

Now I need with function updateTooltipContent to get DISTANCE from OBJECT where is latt=lat:

function updateTooltipContent() {
    var latt = $(this).attr("lat");

    //FIND IN WHICH OBJECT IS latt = lat and from that OBJECT[i] get DISTANCE_ ...

      return "Distance is" + DISTANCE_FROM_PREVIOUS_LOCATION;
    }
});

Is there any way to do that? So I need to call function nArray which will create bigArray and from thee find in which objet is latt = lat and get from that OBJECT[i] DISTANCE

0

1 Answer 1

1

When nArray function returns the bigArray you just need to loop over it and at each iteration check if latt == lat.

var bigArray = nArray();
var distance = 0.00;

for(var x = 0; x < bigArray.length; x++)
{
    if(bigArray[x].lat == latt)
    {
        distance = bigArray[x].DISTANCE_FROM_PREVIOUS_OBJECT_LOCATION;
        break; // no point doing anymore loops as we've found the answer
    }        
}

Might need to use the parseFloat function in js depending on how you are dealing with the numbers.

Sign up to request clarification or add additional context in comments.

2 Comments

Just wrap the parseFloat function around bigArray[x].lat. Check this link for more examples of its use w3schools.com/jsref/jsref_parsefloat.asp
yes but whats look like in my example? THANKS very much, I will see is this working for me.

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.