I am new to React JS (Javascript) and getting problems during merge the previous records with the new records in Pagination.
Below is the code:-
First Page Result
{
"status": 200,
"error": null,
"message": null,
"result": {
"data": [{
"SuraID": 116,
"ChapterID": 2,
"SuraName": "The Cow",
"Sajda": 0,
"Ayah": 286,
"Latin": "Al-Baqara",
"AyahText": [{
"id": 6283,
"text": "O children of Israel, remember the favours I bestowed on you. So keep your pledge to Me, and I will mine to you, and be fearful of Me, ",
"found": "1"
},
{
"id": 6290,
"text": "Remember, O children of Israel, the favours I bestowed on you, and made you exalted among the nations of the world. ",
"found": "1"
}
]
}],
"totalFound": 598,
"prev_page_url": "1",
"next_page_url": 2,
"totalPages": 27,
"percentage": 0.38390180331131357
}
Second Page Result
{
"status": 200,
"error": null,
"message": null,
"result": {
"data": [{
"SuraID": 116,
"ChapterID": 2,
"SuraName": "The bufallow",
"Sajda": 0,
"Ayah": 286,
"Latin": "Al-Baqara",
"AyahText": [{
"id": 6283,
"text": "O children of Israel, remember the favours I bestowed on you. So keep your pledge to Me, and I will mine to you, and be fearful of Me, ",
"found": "1"
},
{
"id": 6290,
"text": "Remember, O children of Israel, the favours I bestowed on you, and made you exalted among the nations of the world. ",
"found": "1"
}
]
}
"totalFound": 598,
"prev_page_url": "2",
"next_page_url": 3,
"totalPages": 27,
"percentage": 0.38390180331131357
}
Final Result Should like the below JSON
{
"status": 200,
"error": null,
"message": null,
"result": {
"data": [{
"SuraID": 116,
"ChapterID": 2,
"SuraName": "The Cow",
"Sajda": 0,
"Ayah": 286,
"Latin": "Al-Baqara",
"AyahText": [{
"id": 6283,
"text": "O children of Israel, remember the favours I bestowed on you. So keep your pledge to Me, and I will mine to you, and be fearful of Me, ",
"found": "1"
},
{
"id": 6290,
"text": "Remember, O children of Israel, the favours I bestowed on you, and made you exalted among the nations of the world. ",
"found": "1"
}
]
}, {
"SuraID": 116,
"ChapterID": 2,
"SuraName": "The Cow",
"Sajda": 0,
"Ayah": 286,
"Latin": "Al-Baqara",
"AyahText": [{
"id": 6283,
"text": "O children of Israel, remember the favours I bestowed on you. So keep your pledge to Me, and I will mine to you, and be fearful of Me, ",
"found": "1"
},
{
"id": 6290,
"text": "Remember, O children of Israel, the favours I bestowed on you, and made you exalted among the nations of the world. ",
"found": "1"
}
]
}],
"totalFound": 598,
"prev_page_url": "1",
"next_page_url": 2,
"totalPages": 27,
"percentage": 0.38390180331131357
}
Pseudo code:
let firstPageData = //from 1 fetch and after JSON.parse(data);
let secondPageData = //from 2 fetch and after JSON.parse(data);
let mergedPage= [...firstPageData,...secondPageData ];
or
let mergedPage= firstPageData.concat(secondPageData);
I am trying to figure out the proper syntax to push a set of array values to a new array after making an API call. I am trying to combine 2 paths from one API call into a single array to use for an image slider for a product page on an eCommerce site. Here's what I have so far. I need help with the second path and push to array. Any input would be appreciated!
JavaScript
$.getJSON("item-data.json", function(results) {
$.each(results.CatalogEntryView, function(index, item) {
var slideshowArray = [];
//the first path - this works
slideshowArray.push(item.Images[0].PrimaryImage[0].image)
//the second path
$.each(item.Images[0].AlternateImages[0].image, function(k, v) {
slideshowArray.push(v);
});
//used to verify the successful array push
console.log(slideshowArray.length);
});
});
JSON
{
"CatalogEntryView": [
{
"CustomerReview": [
{
"Con": [
{
"RatableAttributes": [
{
"description": "easy_to_use",
"name": "EASY_TO_USE",
"value": "4"
},
{
"description": "quality",
"name": "QUALITY",
"value": "1"
},
{
"description": "value",
"name": "VALUE",
"value": "1"
}
],
"datePosted": "Mon Mar 11 13:13:55 UTC 2013",
"overallRating": "1",
"review": "Less than 2 months after purchase it completely stopped working. First it wouldn't detect the pitcher when trying to blend a significant amount, a couple weeks later it wouldn't detect the single serve cup. ",
"reviewKey": "b326b0d6-e6ae-4ec5-8080-720f0ad741af",
"screenName": "New York",
"title": "Very unhappy"
}
],
"ConsolidatedRatableAttributes": [
{
"description": "Quality",
"name": "QUALITY",
"value": "4"
},
{
"description": "Easy to Use",
"name": "EASY_TO_USE",
"value": "4.5"
},
{
"description": "Value",
"name": "VALUE",
"value": "3.5"
}
],
"Pro": [
{
"RatableAttributes": [
{
"description": "easy_to_use",
"name": "EASY_TO_USE",
"value": "5"
},
{
"description": "quality",
"name": "QUALITY",
"value": "5"
},
{
"description": "value",
"name": "VALUE",
"value": "5"
}
],
"datePosted": "Thu Apr 18 19:42:19 UTC 2013",
"overallRating": "5",
"review": "This blender works amazingly, and blends within seconds. The single serve cups also work really well for smoothies or protein shakes!",
"reviewKey": "d602bcdf-53be-4769-94da-3b3fd2517d21",
"screenName": "Eric",
"title": "Fantastic Blender"
}
],
"Reviews": [
{
"RatableAttributes": [
{
"description": "easy_to_use",
"name": "EASY_TO_USE",
"value": "4"
},
{
"description": "quality",
"name": "QUALITY",
"value": "1"
},
{
"description": "value",
"name": "VALUE",
"value": "1"
}
],
"city": "NYC",
"customerId": "110657105",
"datePosted": "Mon Mar 11 13:13:55 UTC 2013",
"helpfulVotes": "39",
"overallRating": "1",
"review": "Less than 2 months after purchase it completely stopped working. First it wouldn't detect the pitcher when trying to blend a significant amount, a couple weeks later it wouldn't detect the single serve cup. ",
"reviewKey": "b326b0d6-e6ae-4ec5-8080-720f0ad741af",
"screenName": "New York",
"state": "NY",
"title": "Very unhappy",
"totalComments": "0",
"totalVotes": "52"
},
{
"Comments": [
{
"city": "",
"commentKey": "CommentKey:ffcefb66-381a-4985-b869-9fcfdd26e7cc",
"commentText": "Separating the men from the boys, separating the amateurs from the professionals when it comes to blenders, when you revealed to us that, -It doesn't pulverize seeds-.I really need a good blender, but there is No way that I would buy this blender now. Thank you so much, Jon",
"postedDate": "Thu Oct 10 04:17:50 UTC 2013",
"screenName": "JON",
"userKey": "118863321",
"userTier": "Trusted"
}
],
"RatableAttributes": [
{
"description": "quality",
"name": "QUALITY",
"value": "2"
},
{
"description": "easy_to_use",
"name": "EASY_TO_USE",
"value": "3"
},
{
"description": "value",
"name": "VALUE",
"value": "2"
}
],
"city": "Idaho Falls",
"customerId": "116317693",
"datePosted": "Sun Sep 01 03:18:11 UTC 2013",
"helpfulVotes": "16",
"overallRating": "2",
"review": "This blender is not superior to other smoothie blenders, It doesn't pulverize seeds and leaves green smoothies chunky with a lot of pulp. The single serve concept is amazing, however, my single serve cup began to break right from the start. The prongs became chipped because of the difficulty of screwing it in and out of the base. It won't blend for more than a minute without smelling like burned rubber. While the single serve seemed to blend more smoothly, it didn't hold much, especially when adding ice. I was very disappointed and so I returned it,",
"reviewKey": "399853f3-4451-40a8-bcd6-bda2d814d9f4",
"screenName": "London",
"state": "ID",
"title": "Very Disappointed",
"totalComments": "1",
"totalVotes": "21"
},
{
"RatableAttributes": [
{
"description": "easy_to_use",
"name": "EASY_TO_USE",
"value": "5"
},
{
"description": "quality",
"name": "QUALITY",
"value": "5"
},
{
"description": "value",
"name": "VALUE",
"value": "5"
}
],
"city": "Oakland",
"customerId": "100025104",
"datePosted": "Thu Apr 18 19:42:19 UTC 2013",
"helpfulVotes": "10",
"overallRating": "5",
"review": "This blender works amazingly, and blends within seconds. The single serve cups also work really well for smoothies or protein shakes!",
"reviewKey": "d602bcdf-53be-4769-94da-3b3fd2517d21",
"screenName": "Eric",
"state": "CA",
"title": "Fantastic Blender",
"totalComments": "0",
"totalVotes": "10"
},
{
"RatableAttributes": [
{
"description": "quality",
"name": "QUALITY",
"value": "5"
},
{
"description": "easy_to_use",
"name": "EASY_TO_USE",
"value": "5"
},
{
"description": "value",
"name": "VALUE",
"value": "5"
}
],
"city": "Cambridge",
"customerId": "172227",
"datePosted": "Sat Jan 18 01:20:36 UTC 2014",
"helpfulVotes": "9",
"overallRating": "5",
"review": "I am blown away by this blender. It obliterates ice and frozen fruit - and blends fresh fruits to smooth perfection. It even makes quick work of fresh ginger and tough greens. I did a ton of research before settling on the Ninja. This was a splurge for me - and I spent the extra money to get the single serve cups, thinking I'd take my smoothie to work every morning. But my husband is totally hooked on smoothies now too, so the big pitcher is getting regular use. Tried it out for margaritas tonight... half a lime, half a lemon, half an orange with tequila, honey and ice... unbelievably good. Haven't tried it for soup or sauce yet, but can hardly wait.\n\nI'm impressed by features such as the suction cup feet, the snap-seal lid, and the sensor that prevents the machine from being turned on without the top in place. It cleans up nicely too. \n\nBottom line: I can't stop raving about this thing and have recommended it to all my friends and family.",
"reviewKey": "d8e9ac59-6c3a-47be-8b87-f912715ccd18",
"screenName": "E",
"state": "MA",
"title": "Couldn't be happier",
"totalComments": "0",
"totalVotes": "9"
},
{
"Comments": [
{
"city": "",
"commentKey": "CommentKey:a5b92fc8-ec2a-4772-b4ea-3cf4d473015b",
"commentText": "THANK YOU, THANK YOU!!!!! YOU JUST GAVE ME THE BEST REASON TO -- NOT BUY -- THIS THING ! THANK YOU, JON",
"postedDate": "Thu Oct 10 03:44:47 UTC 2013",
"screenName": "JON",
"userKey": "118863321",
"userTier": "Trusted"
}
],
"RatableAttributes": [
{
"description": "quality",
"name": "QUALITY",
"value": "1"
},
{
"description": "easy_to_use",
"name": "EASY_TO_USE",
"value": "1"
},
{
"description": "value",
"name": "VALUE",
"value": "1"
}
],
"city": "new york",
"customerId": "116426870",
"datePosted": "Thu Jun 06 04:49:37 UTC 2013",
"helpfulVotes": "38",
"overallRating": "1",
"review": " Upon using this blender it turns out that the food gets into a deep hole at the bottom of the blade assembly , which fits on top of the rotating spindle, which cannot be cleaned. No amount of rinsing or dish washer washing can get to it. A special thin and long brush would be required. Such food deposits can quickly become a place for bacteria growth and accumulate soap from dishwasher etc. A radical design change and going back to the drawing board is required, which Ninja would be unwilling to do. Very poor and harmful product",
"reviewKey": "49add669-1256-4894-9fce-9e0464342887",
"screenName": "gourmet",
"state": "NY",
"title": "bacteria hazard",
"totalComments": "1",
"totalVotes": "69"
},
{
"RatableAttributes": [
{
"description": "quality",
"name": "QUALITY",
"value": "5"
},
{
"description": "easy_to_use",
"name": "EASY_TO_USE",
"value": "5"
},
{
"description": "value",
"name": "VALUE",
"value": "5"
}
],
"city": "Wilmington ",
"customerId": "115016455",
"datePosted": "Sun Mar 16 13:54:36 UTC 2014",
"helpfulVotes": "5",
"overallRating": "5",
"review": "Right out of the box I love this thing. You have to read the instructions: it indicates you must pulse several times THEN blend in order to get the smooth consistency. I'm going now to google soups to make. I'll add on to my review once I've tried more stuff. I know some folks had problems, I can say with total confidence that Ninja backs up what they make. I have a vacuum, steamer and iron and I broke the vacuum and they still fixed it for free. Easy peasy. Be sure to register your purchase. Peace. ",
"reviewKey": "bf2283a9-37a1-46e2-b9b4-3edb757d5375",
"screenName": "Sandra",
"state": "DE",
"title": "Great Blender",
"totalComments": "0",
"totalVotes": "5"
},
{
"RatableAttributes": [
{
"description": "quality",
"name": "QUALITY",
"value": "5"
},
{
"description": "easy_to_use",
"name": "EASY_TO_USE",
"value": "5"
},
{
"description": "value",
"name": "VALUE",
"value": "5"
}
],
"city": "Tucson",
"customerId": "119946555",
"datePosted": "Thu Jan 30 18:50:22 UTC 2014",
"helpfulVotes": "6",
"overallRating": "5",
"review": "My daughter received this Ninja blender and she absolutely loves it. My grandson has Autisim and has very sensitive taste buds. With the Ninja my daughter is able to puree his homemade soups, & refried beans. Life is a little easier for my daughter & him. She is in heaven. \n",
"reviewKey": "7c7ef8c0-e227-45a5-86cd-c29adeb0bd2a",
"screenName": "Flora",
"state": "AZ",
"title": "Ninja Blender",
"totalComments": "0",
"totalVotes": "7"
},
{
"RatableAttributes": [
{
"description": "quality",
"name": "QUALITY",
"value": "4"
},
{
"description": "easy_to_use",
"name": "EASY_TO_USE",
"value": "5"
},
{
"description": "value",
"name": "VALUE",
"value": "5"
}
],
"city": "Minneapolis",
"customerId": "109690154",
"datePosted": "Sun Jan 12 17:41:43 UTC 2014",
"helpfulVotes": "4",
"overallRating": "5",
"review": "I have to assume that the negative reviewers received an unfortunate "lemon" blender... that, or they didn't read the instruction manual, because I love my Ninja and definitely recommend it.\n\nI've had this blender for over a year and it still works as wonderfully as the day I bought it. I use it primarily for making smoothies, everything from green monsters to peanut butter protein shakes to frozen fruit & yogurt smoothies with chia seeds on top.\n\nIt's like having Jamba Juice in my kitchen, but without the long line of snap-chatting teenagers.\n\nI frequently use the to-go cups to blend and take with me in the car. If you are in the camp lamenting that it doesn't hold enough, you probably also expect that once blended, it will be as full as you originally (over)stuffed it.\n\nRespect the max fill line, people, or use the full-size blender if you are going for NYC Big Gulp size.\n\nI will say, that if you are looking to seriously juice, this is not the blender for you. \n\nIt might take a little experimentation to get the right ratio of liquid to solid\/frozen for a perfectly smooth blend, but once you figure out what works for you, it's easy!",
"reviewKey": "9e0322d2-256e-46a5-80dc-b4468e58359b",
"screenName": "Kari",
"state": "MN",
"title": "Love this blender!",
"totalComments": "0",
"totalVotes": "4"
},
{
"RatableAttributes": [
{
"description": "quality",
"name": "QUALITY",
"value": "5"
},
{
"description": "easy_to_use",
"name": "EASY_TO_USE",
"value": "5"
},
{
"description": "value",
"name": "VALUE",
"value": "5"
}
],
"city": "Houston",
"customerId": "116412794",
"datePosted": "Wed Jun 05 14:26:21 UTC 2013",
"helpfulVotes": "5",
"overallRating": "5",
"review": "[...]\nAll the parts are well made and good quality. The only thing that seems a little flimsy would be the drinking tops for the single serve cups, but those don't even matter because all you are doing is drinking from the tops. All the rest of the machine is top notch.\n\nThis blender is powerful, quiet and very easy to clean. \n\n[...]\nYou will not regret buying this machine. ",
"reviewKey": "4cc67e87-6754-4cab-8eb7-fb3bd738c16c",
"screenName": "Te-Ann",
"state": "TX",
"title": "LOVE LOVE LOVE!!!!",
"totalComments": "0",
"totalVotes": "6"
},
{
"RatableAttributes": [
{
"description": "quality",
"name": "QUALITY",
"value": "5"
},
{
"description": "easy_to_use",
"name": "EASY_TO_USE",
"value": "5"
},
{
"description": "value",
"name": "VALUE",
"value": "4"
}
],
"city": "CENTREVILLE",
"customerId": "102170259",
"datePosted": "Thu Jan 30 05:33:15 UTC 2014",
"helpfulVotes": "3",
"overallRating": "5",
"review": "I'm not sure why there are so many negative reviews about this blender on Target's website, but it's a great blender. The first blender I've own that actually crushes the ice completely! Perfect for shakes!",
"reviewKey": "3e810dba-638f-4146-aee8-190a741d86d5",
"screenName": "SL",
"state": "VA",
"title": "Fantastic blender!!",
"totalComments": "0",
"totalVotes": "3"
}
],
"consolidatedOverallRating": "4",
"totalPages": "2",
"totalReviews": "14"
}
],
"DPCI": "072-04-1840",
"Images": [
{
"AlternateImages": [
{
"image": "http:\/\/target.scene7.com\/is\/image\/Target\/14263758_Alt01"
},
{
"image": "http:\/\/target.scene7.com\/is\/image\/Target\/14263758_Alt02"
},
{
"image": "http:\/\/target.scene7.com\/is\/image\/Target\/14263758_Alt03"
},
{
"image": "http:\/\/target.scene7.com\/is\/image\/Target\/14263758_Alt04"
},
{
"image": "http:\/\/target.scene7.com\/is\/image\/Target\/14263758_Alt05"
},
{
"image": "http:\/\/target.scene7.com\/is\/image\/Target\/14263758_Alt06"
},
{
"image": "http:\/\/target.scene7.com\/is\/image\/Target\/14263758_Alt07"
}
],
"PrimaryImage": [
{
"image": "http:\/\/target.scene7.com\/is\/image\/Target\/14263758"
}
],
"imageCount": "8",
"source": "internal"
}
],
"ItemDescription": [
{
"features": [
"<strong>Wattage Output:<\/strong> 1100 Watts",
"<strong>Number of Speeds:<\/strong> 3 ",
"<strong>Capacity (volume):<\/strong> 72.0 Oz.",
"<strong>Appliance Capabilities:<\/strong> Blends",
"<strong>Includes:<\/strong> Travel Lid",
"<strong>Material:<\/strong> Plastic",
"<strong>Finish:<\/strong> Painted",
"<strong>Metal Finish:<\/strong> Chrome",
"<strong>Safety and Security Features:<\/strong> Non-Slip Base",
"<strong>Care and Cleaning:<\/strong> Easy-To-Clean, Dishwasher Safe Parts"
]
}
],
"Offers": [
{
"OfferPrice": [
{
"currencyCode": "USD",
"formattedPriceValue": "$139.99",
"priceQualifier": "Online Price",
"priceValue": "13999"
}
]
}
],
"POBoxProhibited": "We regret that this item cannot be shipped to PO Boxes.",
"PackageDimension": [
{
"name": "length",
"unit": "IN",
"value": "17.4"
},
{
"name": "width",
"unit": "IN",
"value": "12.4"
},
{
"name": "height",
"unit": "IN",
"value": "9.9"
},
{
"name": "weight",
"unit": "LB",
"value": "10.85"
}
],
"Promotions": [
{
"Description": [
{
"legalDisclaimer": "Offer available online only. Offer applies to purchases of $50 or more of eligible items across all categories. Look for the "SPEND $50: SHIPS FREE" logo on eligible items. Some exclusions apply. Items that are not eligible are subject to shipping charges. $50 purchase is based on eligible merchandise subtotal. Items that are not eligible, GiftCards, e-GiftCards, gift wrap, tax and shipping and handling charges will not be included in determining merchandise subtotal. Offer valid for orders shipping within the 48 contiguous states, as well as APO\/FPO and for Standard and To the Door shipping methods only. Not valid on previous orders.",
"shortDescription": "SPEND $50, GET FREE SHIPPING"
}
],
"endDate": "2014-05-25 06:59:00.001",
"promotionIdentifier": "10736506",
"promotionType": "Buy catalog entries from category X, get shipping at a fixed price",
"startDate": "2014-05-18 07:00:00.001"
},
{
"Description": [
{
"legalDisclaimer": "Receive a $25 gift card when you buy a Ninja Professional Blender with single serve blending cups or a Ninja MEGA Kitchen System. Not valid on previous orders. On your order summary, the item subtotal will reflect the price of the qualifying item plus the amount of the free gift card, followed by a discount given for the amount of the free gift card. Your price on the order summary will be the price of the qualifying item (the total charges for the qualifying item and gift card). Your account will actually be charged the amount of the qualifying item reduced by the amount of the gift card, and a separate charge for the amount of the gift card. The gift card will be sent to the same address as your order and will ship separately. If you want to return the item you purchased to a Target Store, you may either keep the gift card and just return the qualifying item (you will be refunded the amount of the qualifying item reduced by the amount of the gift card), or you can return the qualifying item and the gift card for a full refund using the online receipt. If you return the item you purchased by mail, keep the gift card; you will be refunded the amount of the qualifying item reduced by the amount of the gift card. Offer expires 05\/24\/14 at 11:59pm PST.",
"shortDescription": "$25 gift card with purchase of a select Ninja Blender"
}
],
"endDate": "2014-05-25 06:59:00.001",
"promotionIdentifier": "10730501",
"promotionType": "Multiple Items Free Gift",
"startDate": "2014-05-11 07:00:00.001"
}
],
"ReturnPolicy": [
{
"ReturnPolicyDetails": [
{
"guestMessage": "View our return policy",
"policyDays": "100",
"user": "Regular Guest"
},
{
"guestMessage": "View our return policy",
"policyDays": "120",
"user": "Best Guest"
}
],
"legalCopy": "refund\/exchange policy<br\/><br\/><p style=\"font-size:13px;\">Most unopened items in new condition returned within 90 days will receive a refund or exchange. Some items have a modified return policy that is less than 90 days. Those items will either show a \"return by\" date or \"return within\" day range under the item on your receipt or packing slip and in the \"Item details, shipping\" tab if purchased on Target.com. Items that are opened or damaged or do not have a packing slip or receipt may be denied a refund or exchange. All bundled items must be returned with all components for a full refund. Bundle components may not all have the same return policy; please check your packing slip for details. Some items, such as gift cards, digital items are never returnable. <br \/><br \/>See the <a href=\"http:\/\/www.target.com\/HelpContent?help=\/sites\/html\/TargetOnline\/help\/returns_and_refunds\/returns_and_refunds.html\">Target return policy<\/a> for complete information.<\/p><br\/>"
}
],
"UPC": "622356532099",
"applyCouponLink": "false",
"buyable": "true",
"callOutMsg": "FREE $25 GIFT CARD",
"catEntryId": "205273068",
"classId": "04",
"department": "072",
"eligibleFor": "ADD_TO_CART",
"inventoryCode": "0",
"inventoryStatus": "Online",
"itemId": "1840",
"itemType": "ItemBean",
"manufacturer": "Euro Pro",
"manufacturerPartNumber": "BL660",
"packageQuantity": "null ",
"partNumber": "14263758",
"purchasingChannel": "Sold Online + in Stores",
"purchasingChannelCode": "0",
"shortDescription": "For the first time EVER - you get the same professional performance power in the Single Serve as well as the XL 72 oz pitcher! The Ninja\u2122 Professional Blender with Single Serve Blending Cups allow you to crush ice into snow, blend whole fruits and vegetables into nutritious beverages, and create resort style blended drinks! Full size blender performance now in individual cups.",
"title": "Ninja\u2122 Professional Blender with Single Serve Blending Cups",
"webclass": "Small Appliances"
}
]
}
How can I append value to an object from another object without replacement?
I am trying to append a value from ObjectA to ObjectB as the name of a child object.
This is ObjectA.
As you can tell, ObjectA has 4 child object and each associates with a uid.
This is ObjectB
So I'm trying to map the uid of each child from ObjectA to ObjectB.
This is what the ideal code would look like
Object.keys(ObjectA).forEach(
(key) => _.assign(ObjectB, {'Product 07': true})
)
I tried to inject each ObjectB iteration to the source placeholder ES6 string interpolation but it would fail, like so.
Object.keys(ObjectA).forEach(
(key) => _.assign(ObjectB, {`${basketObject[key].uid}`: true})
)
Source(JSON)
Please use this code to convert Object of objects to Object of arrays with _.mapValues to generate uid from Object name
var ObjectA = _.mapValues(data, (val, index) => {
return { ...val, index }
})
{
"Product": {
"Product 01": {
"approved": true,
"brand": "MANGO",
"category": "Woman",
"color": "Black,Bright Pink",
"description": "Rounded neck Chain detail Slit detail Zip fastening on the back section Inner lining · Side length 117.0 cm · Back length 135.5 cm These measures have been calculated for a S size.",
"imageURL": "https://s11.postimg.org/612lpusf7/73025590_80.jpg",
"name": "Chain Collar Dress",
"price": 499,
"purchasedUser": {
"mgzQBxjF9NNVACh18ID1xDPtrwH2": true
},
"size": "S,M,L,XL"
},
"Product 02": {
"approved": true,
"brand": "MANGO",
"category": "Man",
"color": "Grey",
"description": "Modern coat that suits every man",
"imageURL": "https://s4.postimg.org/vub6umtlp/73079700_99.jpg",
"name": "Tailored wool-blend overcoat",
"price": 899,
"purchasedUser": {
"mgzQBxjF9NNVACh18ID1xDPtrwH2": true
},
"size": "S,M,L,XL"
},
"Product 03": {
"approved": true,
"brand": "MANGO",
"category": "Kid",
"color": "Dark Navy, Offwhite, Light Pink,Medium Heather Grey",
"description": "Cotton fabric Spots print Rounded neck Short sleeve Embroidered Mango logo Decorated with sequins",
"imageURL": "https://s16.postimg.org/xkpg8qypx/73003605_56.jpg",
"name": "Logo cotton t-shirt",
"price": 29.9,
"purchasedUser": {
"mgzQBxjF9NNVACh18ID1xDPtrwH2": true
},
"size": "3-4 years,5-6 years, 7-8 years, 9-10 years, 11-12 years, 13-14 years"
},
"Product 04": {
"approved": true,
"brand": "UNIQLO",
"category": "Woman",
"color": "Red, Natural, Navy",
"description": "This comfortable women's shirt features the distinctive soft, warm, fuzzy feel of brushed 100% cotton flannel material. It looks great as a shirt or light outer layer, and the slightly loose cut gives it a relaxed style. The classic casual plaid design is available in a variety of colors.",
"imageURL": "https://s11.postimg.org/48sak0lmr/69_180861.jpg",
"name": "Flannel Check Long Sleeve Shirt",
"price": 79.9,
"size": "S,M,L,XL"
},
"Product 05": {
"approved": true,
"brand": "UNIQLO",
"category": "Kid",
"color": "Offwhite",
"description": "Star Wars™ A long time ago in a galaxy far, far awayLong after the Jedi Knights have perished, young Luke Skywalker has a fateful encounter with Princess Leia, a leader of the Rebel forces. Luke and Leia fight alongside Han Solo, Chewbacca, R2-D2 and C-3PO against the evil forces of Darth Vader to help restore peace in the galaxy. starwars.com © & ™ Lucasfilm Ltd. MATERIAL100% Cotton CAREMachine wash cold",
"imageURL": "https://s21.postimg.org/xdojmkx1z/01_185878.jpg",
"name": "BOYS STAR WARS Short Sleeve Graphic T-Shirt",
"price": 39.9,
"size": "110cm,120cm,130cm,140cm,150cm"
},
"Product 06": {
"approved": true,
"brand": "UNIQLO",
"category": "Man",
"color": "White,Dark Grey, Navy",
"description": "This amazing men's polo is made from next-generation, high-tech DRY-EX material. It dries sweat incredibly quickly to keep you feeling smooth, dry, and comfortable. The soft, cotton-like texture and cut allow for easy movement and combined, offer for superb comfort. In a fashionable striped pattern, perfect for warm-weather casual looks. MATERIAL[08Dark Gray] Body: 96% Polyester, 4% Nylon/ Rib: 100% Polyester [Other Colors] 100% Polyester CARE[08Dark Gray] Machine wash cold, gentle cycle [Other Colors] Machine wash cold",
"imageURL": "https://s11.postimg.org/bvm6i0ujn/00_169374.jpg",
"name": "MEN Dry EX Short Sleeve Polo Shirt",
"price": 99.9,
"size": "S,M,L,XL"
},
"Product 07": {
"brand": "FILANTO",
"category": "Woman",
"color": "Black",
"description": "Dress to impress this festive season with our must-have dresses. Our favourite piece for for creating effortlessly chic and glamorous look comes in the form of this delicate lace number. A form-fitting silhouette hugs and flatter your curves beautifully while its minimalist design makes it easy to dress it up or down.",
"imageURL": "https://s15.postimg.org/5qqq9496j/r1_top_fl20131894_002_a_btm_a_fl20131894.jpg",
"name": "Casual Long Dress",
"price": 59.9,
"size": "S,M,L,XL"
},
"Product 08": {
"brand": "HOTSHOTS",
"category": "Kid",
"color": "Off White",
"description": "Update her dress collection with this beautiful printed piece. Offering a short-sleeve design, round neckline and keyhole back button fastening. This dress also showcases a vibrant butterfly print motif. Sweet and demure, all this piece needs is a pair of flats to complete the look.",
"imageURL": "https://s16.postimg.org/ocebpd3h1/ho20129717_002_e_ho20129717.jpg",
"name": "Casual Short Dress Knit",
"price": 29.9,
"size": "4-5,6-7,8-9,10-11"
},
"Product 09": {
"approved": true,
"brand": "PADINI",
"category": "Man",
"color": "White",
"description": "Steeped in a solid white wash, this classic Oxford shirt gets a modern tweak with the addition of stripes across the body. It also features the iconic shirt collar, along with a chest pocket, buttoned cuffs and raised placket. This is the ultimate piece for curating both casual and formal looks.",
"imageURL": "https://s11.postimg.org/cvmbgxg2r/r1_top_pd20131998_003_b_btm_pd20131965_002_b_pd2.jpg",
"name": " Casual Long Sleeve Shirt",
"price": 89,
"size": "XS,S,M,L"
},
"Product 10": {
"brand": "PONEY",
"category": "Kid",
"color": "Navy",
"description": "This navy polo shirt designed with knight prints is Poney's new wardrobe classic. Made from 100% Cotton Fully Comb and Single Jersey. Features a neat polo collar, brown buttons, neckline lining in contrast fabric and leather patches.",
"imageURL": "https://s17.postimg.org/bcpbfwrcf/6j6a5351_2_1_1.jpg",
"name": "KNIGHT POLO SHIRT",
"price": 119,
"size": "7-8,9-10,11-12"
},
"Product 11": {
"brand": "PONEY",
"category": "Kid",
"color": "Navy",
"description": "This beautiful daisy print blouse with contrast sleeves is perfect for your best friend's birthday party. Pair with our \"Poney Daisy Print Jeans\" for a chic contemporary look or our \"Poney Tutu Skirt\" for a classic party look.",
"imageURL": "https://s12.postimg.org/la1o7vtm5/6j6a5327_1.jpg",
"name": "DAISY PRINT BLOUSE",
"price": 76,
"size": "1-2,2-3,3-4,4-5,5-6"
},
"Product 12": {
"brand": "GAMESTERS",
"category": "Kid",
"color": "Grey",
"description": "Ensure your little one is clothed in comfort and style with this super-cool and adorable jogger shorts from Gamester. Complete with an allover repetitive print, elasticated-drawstring waist, two front side pockets and one back pocket. Complement this shorts with any printed tee to complete his look.",
"imageURL": "https://s14.postimg.org/tz3xvg3z5/gm20130687_002_e_gm20130687.jpg",
"name": "Casual Knit Shorts",
"price": 29.9,
"size": "6-7"
}
}
}
it should work
_.mapValues(ObjectA, (val) => {
ObjectB[val.uid] = true;
})
You can use reduce to map your objects to another object;
var objects = [ // Your objects, this is just dummy data
{ uuid: 'Product 01', approved: true },
{ uuid: 'Product 02', approved: true },
{ uuid: 'Product 03', approved: true }
]
var items = objects.reduce(function (prev, current) {
prev[current.uuid] = current.approved;
return prev;
}, {});