开发者

Getting node values from XML and adding them to array?

开发者 https://www.devze.com 2023-02-18 01:21 出处:网络
My XML looks like this: <photo>photo1.jpg</photo> <photo>photo2.jpg</photo> 开发者_如何学C

My XML looks like this:

<photo>photo1.jpg</photo>
<photo>photo2.jpg</photo>
开发者_如何学C

I can get the value of each photo node by doing something like:

var myPhoto = $(this).find('photo').text();

I'm trying to get an array of nodes like so:

myPhotoArray.push(myPhoto); 

When I push this to an array how do I add a comma separator for each node? It prints all the node values out on one line (photo1.jpgphoto2.jpg) Thank you!


Use join when you output:

myPhotoArray.join(",");

Actually, the comma is the default separator, so you could leave it out:

myPhotoArray.join();
0

精彩评论

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

关注公众号