Created
April 19, 2021 13:43
-
-
Save pawarvijay/12e5165b9143c39e0e7e00b8f7f90622 to your computer and use it in GitHub Desktop.
// source https://jsbin.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
const dates = ["monday", "tuesday"] | |
const slots = [{ isCleaned: 'ok' }]; | |
let outPut = {} | |
let ns = slots.map((sl) => { | |
let newObj = { ...sl, isBooked: false } | |
return newObj | |
}) | |
// Solution 1 | |
// dates.forEach((dt) => { | |
// return outPut[dt] = [...ns.map((obj) => { | |
// return { ...obj } | |
// }) | |
// ] | |
// }) | |
// Solution 2 | |
dates.forEach((dt) => outPut[dt] = [...( | |
JSON.parse(JSON.stringify(ns)) | |
)]) | |
outPut['monday'][0]['isBooked'] = true | |
console.log(outPut) | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">const dates = ["monday", "tuesday"] | |
const slots = [{ isCleaned: 'ok' }]; | |
let outPut = {} | |
let ns = slots.map((sl) => { | |
let newObj = { ...sl, isBooked: false } | |
return newObj | |
}) | |
// Solution 1 | |
// dates.forEach((dt) => { | |
// return outPut[dt] = [...ns.map((obj) => { | |
// return { ...obj } | |
// }) | |
// ] | |
// }) | |
// Solution 2 | |
dates.forEach((dt) => outPut[dt] = [...( | |
JSON.parse(JSON.stringify(ns)) | |
)]) | |
outPut['monday'][0]['isBooked'] = true | |
console.log(outPut) | |
</script></body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const dates = ["monday", "tuesday"] | |
const slots = [{ isCleaned: 'ok' }]; | |
let outPut = {} | |
let ns = slots.map((sl) => { | |
let newObj = { ...sl, isBooked: false } | |
return newObj | |
}) | |
// Solution 1 | |
// dates.forEach((dt) => { | |
// return outPut[dt] = [...ns.map((obj) => { | |
// return { ...obj } | |
// }) | |
// ] | |
// }) | |
// Solution 2 | |
dates.forEach((dt) => outPut[dt] = [...( | |
JSON.parse(JSON.stringify(ns)) | |
)]) | |
outPut['monday'][0]['isBooked'] = true | |
console.log(outPut) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment