if (typeof params[value] === 'object') {
getValues(params[value]);
}
const getValues = (params) => {
const array = [];
// keys, потому что нужно делать доп. проверку на ключ
Object.keys(params).reduce((acc, value) => {
if (typeof params[value] === 'object') {
const child = getValues(params[value]);
array.push(child.map(value) => ({ value })))
}
array.push({ value: params[value] });
return array
}, []);
return array;
};
async getAllUsers() {
try {
const { data: users } = await axios.get('http://jsonplaceholder.typicode.com/users')
this.posts = this.posts.map(p => {
p.author = users.find(u => u.id === p.userId)
return p
})
} catch (e) {
console.log(e)
}
}
async getAllUsers() {
try {
const result = await axios.get('http://jsonplaceholder.typicode.com/users')
this.posts = this.posts.map(p => {
p.author = result.data.find(u => u.id === p.userId)
return p
})
} catch (e) {
console.log(e)
}
}
const arr = [1, 3, 4, 6, 7, 8, 9, 10]
const newArr = [...arr, 25]
console.log(newArr) // [1, 3, 4, 6, 7, 8, 9, 10, 25]