0

I have an array storing some data in the following format

var arrayTest = [{
    "firstName": "SOUM!",
     "lastName": "Ghosh"
}, {
    "firstName": "Fred",
    "lastName": "Twilliger"
}, {
    "firstName": "Snoop",
    "lastName": "Krieg"
}

]

I am trying to parse each key items

here is my script

    var html = "";

$.each(arrayTest, function () {
    html + = this.firstName;
});

alert(html);

what am I doing wrong.

Here is my fiddle http://jsfiddle.net/sghoush1/J2ssK/6/

2
  • 2
    f12 for the developer console. It will show your errors. Commented Sep 27, 2013 at 0:45
  • 2
    @CoryDanielson Unless you're on a mac, then it will just pump up the volume or something ;) Commented Sep 27, 2013 at 0:47

3 Answers 3

2

SyntaxError: Unexpected token =

So... you can't have a space between + and =

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

2 Comments

Ahh damn that was it. really simple. I cant believe I missed that. Thanks for pointing that out brian
Yeah, fella. The console is your best friend - it avoids all sorts of questions.
0

String concatenation is so last century

var html = arrayTest.map(function(n) {
    return n.firstName;
}).join('');

Comments

0
$.each(arrayTest, function (i, row) {
    html += row.firstName;
});

http://jsfiddle.net/J2ssK/8/

Comments

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.