开发者

Javascript/JQuery join() method error when using on an array

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", 
       开发者_JAVA技巧 "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.


.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'


Try this (inside your for loop):

Updated:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜