1

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.

2 Answers 2

2

.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'
Sign up to request clarification or add additional context in comments.

Comments

0

Try this (inside your for loop):

Updated:

var joiners;  
for ...
{
joiners += pings[i].joining_profiles[q].name + " ";  
var newText = RTRIM(joiners).split(" ").join(","); 
}

1 Comment

that didnt work... the console is spitting out a parse error because of the var joiners +=

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.