Say I have the following (phoney) feed result from YouTube using the Google Feed API.
{ "feed" : { "author" : "YouTube",
"description" : "",
"entries" : [ { "author" : "Foo",
"categories" : [ "http://gdata.youtube.com/schemas/2007#video",
"Entertainment",
"golf",
"resort"
],
"content" : "Four friends are playing golf. Originally aired on 3/22/2011.",
"contentSnippet" : "Four friends are still playing golf. Originally aired on ...",
"link" : "http://www.linktoyoutubevid.com",
"publishedDate" : "Thu, 24 Mar 2011 07:07:13 -0700",
"title" : "Foobar"
},
.....more feed entries here.....
],
"feedUrl" : "http://www.myyoutubefeed.com",
"link" : "http://www.youtube.com",
"title" : "YouTube Videos",
"type" : "atom10"
},
"m" : "json",
"status" : { "code" : 200 }
}
I want to save this feed result (keeping the JSON format) to a variable, but I first want to strip out elements like categories, content, and contentSnippet. I tried using .splice but kept getting this error: Error: feedResult.feed.entries[0].splice is not a function
Here’s part of my feed call:
feedUrl: opts.sourceUrl,
type: "video",
numEntries: 3,
onFeedLoad: function(feedResult) {
//alert(feedResult);
formatVids(feedResult);
var test = feedResult.feed.entries[0].splice(1,3);
//alert(test);
What’s the correct way to use .splice in this scenario? I could be getting confused as to whether I need to be splicing a JSON string or the JSON object. Is there a better solution?
Thanks!
Unfortunately Object keys are not equivalent to Array keys, in one very important aspect: Order is not preserved when dealing with Object keys.
One way to accomplish what you are trying to do is:
With regard to the IE compatability issue the following is from the MDC documentation on the subject.
Compatibility
map is a recent addition to the ECMA-262 standard; as such it may not be present in other implementations of the standard. You can work around this by inserting the following code at the beginning of your scripts, allowing use of map in implementations which do not natively support it. This algorithm is exactly the one specified in ECMA-262, 5th edition, assuming Object, TypeError, and Array have their original values and that fun.call evaluates to the original value of Function.prototype.call.