0

I have a function that receives an array of objects. The objects are key-value type. The function is for iterating over each array item (object) and diplay its content.

function displayData(myArray) //for debugging
{
    for(var i=0; i<myArray.length;i++)
    {
        console.log(myArray[i]);
    }
}//end displayDay

When I call this function I get this error:

JPM [error]   Message: SyntaxError: missing ) after formal parameters

I checked previous posts that says I must split the array and send it as a string. In this way, I may need to parse the string inside the loop. Is there a simple way to iterate over an array items (objects) in javascript? In arrays, I will set a loop that stops when the length of the array is reached. Can you clarify when shall I stop in a string?

user7945230
  • 1,075
  • 2
  • 13
  • 20
  • 3
    is this only a typo: `myArray.lenght` should be `myArray.length` – caramba May 22 '17 at 09:17
  • http://jsbin.com/quxoselawo/1/edit?js,console — I can't reproduce the problem you describe. No error messages are reported. (It doesn't loop over the array because of the type, but that's beside the point). You need to provide a real [mcve]. – Quentin May 22 '17 at 09:18
  • "I checked previous posts that says I must split the array and send it as a string." — That doesn't make sense. What previous posts say that? "Splitting" is something you do to strings to turn them into arrays, not the other way around. – Quentin May 22 '17 at 09:20
  • @PeterSmith — I can't see any way that would fix the quoted error message. – Quentin May 22 '17 at 09:20
  • The length was a type. The previous posts that suggested split is: [link] (http://stackoverflow.com/questions/13096352/javascript-pass-an-array-to-a-function) but obviously there was not a picked answer in that post. – user7945230 May 22 '17 at 09:36
  • 1
    @user7945230 — That question is full is nonsense because the problem the OP has is very unclear. This is similar to this question where you have some code, and you've quoted an error message, but running the code doesn't result in that error message. You need to provide a [mcve]. – Quentin May 22 '17 at 09:43

0 Answers0