How can I not overwrite data in the object, but add?
-
let contentObject = {items: {}} for (let key in cleanContent) { console.log(cleanContent[key]) contentObject.items = { "name": cleanContent[key].market_hash_name, "price": cleanContent[key].price, "quality": cleanContent[key].ru_rarity } } // В базу данных, очевидно попадает это { "items": { "name": "Little Green Jade Dragon", "price": "58.44", "quality": "Rare" } }
Is it possible to add data to an object without overwriting it? Or should I do it through arraysJavaScript Juliet Spears, Oct 1, 2020 -
let contentObject = {
items: []
}
cleanContent.forEach(content => contentObject.items.push(content));Chase Horton -
contentObject.items = {
...contentObject.items,
"name": cleanContent[key].market_hash_name,
"price": cleanContent[key].price,
"quality": cleanContent[key].ru_rarity
}Anonymous
2 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!