Difference between using .data() and standard JS array

Difference between using .data() and standard JS array

For a script I am writing, I believe I have two options for storing data. I can use a standard JS array created within the JQuery namespace or I can attach that array to a DOM element via the .data() method. My question is simply this. Is there any advantage to storing the array via the .data() method as opposed to just using a JS array? From what I can tell, storing it via .data() would just add unnecessary overhead but I am not sure if that is correct.

If my assumption is correct, can someone give me a few examples of times when it would be advantageous to store data against a DOM element via .data() instead of just using JS variables? I have been trying to get my head around the .data() method and understanding exactly when and where to use it.

 Thanks!