const data = [
{
sessionInformation: [{id: 1, name: "Session first"}],
packageInformation: [{user: "Pol", id: 2}]
},
{
sessionInformation: [{id: 1, name: "Session second"}]
},
{
packageInformation: [{user: "Mike", id: 3}],
sessionInformation: [{id: 1, name: "Session second"}]
}
]
const filtered = [].concat(...data.map(o => {
if (Array.isArray(o.packageInformation)) {
return o.packageInformation
}
return []
}))
console.log({
packageInformation: [].concat(...filtered)
})
const data = {
param: 'value',
key: {
nested: {
double_nested: 'value'
}
},
nested: {
array: ['key 1', 'key 2']
}
}
function getObjectKeys(obj, prefix = '') {
const keys = Object.keys(obj).reduce((res, el) => {
if (Array.isArray(obj[el])) {
return [...res, ...obj[el].map((item, i) => `${prefix}${el}[${i}]`)]
} else if (obj[el] !== null && typeof obj[el] === 'object') {
return [...res, ...getObjectKeys(obj[el], prefix + el + '.')]
} else {
return [...res, prefix + el]
}
}, [])
keys.sort()
return keys
}
const array = getObjectKeys(data)
console.log(array)
/* @flow */
const storage: Object = {}
class MemoryStorage implements MemoryStorageInterface {
get length (): number {
return Object.keys(this.storage).length
}
get storage (): Object {
return storage
}
getItem (key: string): string | null {
return (key in this.storage) ? this.storage[key] : null
}
setItem (key: string, value: any): void {
this.storage[key] = value
}
removeItem (key: string) {
const found = (key in this.storage)
if (found) {
delete this.storage[key]
}
}
clear () {
for (const k in this.storage) {
delete this.storage[k]
}
}
}
export default new MemoryStorage()
async getTickets(slot_id) {
try {
const { data } = await axios.get('/api/tickets/' + slot_id)
return data
} catch (e) {
throw new Error(e)
}
}