📝 Added sandbox (code sketchbook)
This commit is contained in:
parent
b475595f7f
commit
b5daf18b1a
142 changed files with 100702 additions and 0 deletions
31
sandbox/object_methods_js/test.js
Normal file
31
sandbox/object_methods_js/test.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
const iterable = [10, 20, 30]
|
||||
const iterableTwo = { one: 10, two: 'hi', three: [10, 20, 30]}
|
||||
|
||||
const iterateOverArr = (arr) => {
|
||||
for (const [key, value] of Object.entries(arr)) {
|
||||
console.log(`key of Arr: ${key}`, `value of Arr: ${value}`)
|
||||
}
|
||||
}
|
||||
|
||||
const iterateOverObj = (obj) => {
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
console.log(`key of Obj: ${key}`, `value of obj: ${value}`)
|
||||
}
|
||||
}
|
||||
|
||||
const callIterable = (data) => {
|
||||
if (Array.isArray(data)) {
|
||||
iterateOverArr(data)
|
||||
} else if (typeof data === 'object'){
|
||||
iterateOverObj(data)
|
||||
} else {
|
||||
const type = typeof data
|
||||
console.log(`${data} is not an array or object`)
|
||||
console.log(`${data} is a ${type}`)
|
||||
}
|
||||
}
|
||||
|
||||
callIterable(iterable)
|
||||
callIterable(iterableTwo)
|
||||
callIterable('test')
|
||||
callIterable(5)
|
||||
Loading…
Add table
Add a link
Reference in a new issue