Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "pimage": [
- {
- "limage": "http://images.bestbuy.com/BestBuy_US/images/products/7306/7306011_sb.jpg",
- "timage": "http://images.bestbuy.com/BestBuy_US/images/products/7306/7306011_s.gif",
- "mimage": "http://images.bestbuy.com/BestBuy_US/images/products/7306/7306011fp.gif",
- "lfimage": "http://img.bbystatic.com/BestBuy_US/images/products/7306/7306011_sa.jpg"
- }
- ]
- }
- {
- "pimage": [
- {
- "limage": "http://images.bestbuy.com/BestBuy_US/images/products/7306/7306011_sb.jpg"
- },
- {
- "limage": "http://images.bestbuy.com/BestBuy_US/images/products/7306/7306011_s.gif"
- },
- {
- "limage": "http://images.bestbuy.com/BestBuy_US/images/products/7306/7306011_s.gif"
- },
- {
- "limage": "http://images.bestbuy.com/BestBuy_US/images/products/7306/7306011_s.gif"
- }
- ]
- }
- var myObj = {
- "pimage": [
- {
- "limage": "http://images.bestbuy.com/BestBuy_US/images/products/7306/7306011_sb.jpg",
- "timage": "http://images.bestbuy.com/BestBuy_US/images/products/7306/7306011_s.gif",
- "mimage": "http://images.bestbuy.com/BestBuy_US/images/products/7306/7306011fp.gif",
- "lfimage": "http://img.bbystatic.com/BestBuy_US/images/products/7306/7306011_sa.jpg"
- }
- ]
- }
- var myFunc = function(obj) {
- var keys = Object.keys(obj.pimage[0]);
- var newObj = {"pimage":[]};
- keys.forEach(function(k) {
- var newImg = {};
- newImg['limage'] = k;
- newObj.pimage.push(newImg);
- });
- return newObj;
- }
- console.log(myFunc(myObj));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement