Search code examples
javascriptarraysvariable-length-array

How to handle an dynamic array?


I want to show up the names of the members of an array "path" in my console.

console.log("start: ", path[0].name, "second: ", path[1].name, "third: ", path[2]name, ....)

But the problem is, that my array always changes it's size (clicking algorithm), that means sometimes it has the lenght 4 or sometimes 8 ect. How can i adjust the console.log code to this dynamic array? Thanks so much!


Solution

  • Something like this:

    var path = ['Prit', 'Bab', 'Nav']
    var item = ["first","second", "third"]; 
    for (i = 0; i < path.length;i++){
        console.log(item[i] + ":" + path[i])
    }