Skip to content

Instantly share code, notes, and snippets.

@pawarvijay
Created April 19, 2021 13:43
Show Gist options
  • Save pawarvijay/12e5165b9143c39e0e7e00b8f7f90622 to your computer and use it in GitHub Desktop.
Save pawarvijay/12e5165b9143c39e0e7e00b8f7f90622 to your computer and use it in GitHub Desktop.
// source https://jsbin.com
<!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>
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