views:

35

answers:

2

Hello All,

I'm trying to loop through my JSON array and assign a specific key of each element into a variable:

Here is the array:

"joining_profiles": [
      {
        "pic": "http://graph.facebook.com/832332325303/picture", 
        "id": 3, 
        "name": "Test2 Gmail"
      }, 
      {
        "pic": "http://graph.facebook.com/620223232354388/picture", 
        "id": 81, 
        "name": "Lawson G."
      }, 
      {
        "pic": "http://graph.facebook.com/6693273223239/picture", 
        "id": 83, 
        "name": "Mark Zuckerberg"
      }
    ]

Here is my javascript:

for (var q = 0; q < pings[i].joining_profiles.length; q++) {
          var joiners = pings[i].joining_profiles[q].name;
          joiners.join();

Basically I need to assign each "name" entry into a joined variable separated by a comma to use in a closured function.

The error im getting from the console is:

TypeError: Result of expression 'joiners.join' [undefined] is not a function.

A: 

Try this (inside your for loop):

Updated:

var joiners;  
for ...
{
joiners += pings[i].joining_profiles[q].name + " ";  
var newText = RTRIM(joiners).split(" ").join(","); 
}
Sidharth Panwar
that didnt work... the console is spitting out a parse error because of the var joiners +=
fordays
See the udpated code.
Sidharth Panwar
+1  A: 

.name is a string. You're calling .join() on a string which doesn't have a join method.

''.join()
TypeError: Object  has no method 'join'
meder