Javascript splitting is not a function

Hi friends, I am using javascript sdk to post users' friends on the wall using jQuery facebook multi friend selector, but I am getting this error. friendId.split is not a function. Here is my code

function recommendToFriend(pic, url, friendId, fromName) { alert(friendId); var friendList ; pFriend = new Array(); pFriend = friendId.split(','); for( x in pFriend ) { alert(pFriend[x]); var publish = { method:'feed', picture:pic, link:url, name:'SHARP Product Recommend', caption: fromName + 'has recommend a product to you via Sharp Expert lounge', }; FB.api('/'+pFriend[x]+'/feed', 'post', publish, function(resp) { if( !response || response.error ) alert('Unable to share'); else alert('Successfully posted to firends wall'); }); } } 

In the warning window, I received the divided identifiers of friends, so I use the column message of the function on each user wall separately, I do not know what is wrong here, please help me

+6
source share
3 answers

You can move JS objects like this

 for (var key in friendid) { var obj = friendid[key]; for (var prop in obj) { alert(prop + " = " + obj[prop]); } } 

Hope this helps

alternative

 for( var x in friendId ) { alert(friendId[x]); // this would be your desired value } 
+2
source

Most likely friendID already an array. If you call alert , the array is converted to a string and becomes a comma-separated list of values.

Note that converting an array to a string does not match the JSON.stringify call (where you also get brackets and double quotes around elements when they are strings)

+7
source

The JavaScript split() function is intended for a type string, for example, for example.

 var friendid='1,34,67'; 

As VisioN tells you, when you warn an array, you get comma separated values.

+4
source

Source: https://habr.com/ru/post/915667/


All Articles