Answer the question
In order to leave comments, you need to log in
How to overwrite values in an array of objects?
I have an array of objects
let data = [
{
id: 1,
title: "Product 1",
images: [
"http://www.nicolethemes.com/sapphire-html/products/dress1home.jpg",
"http://www.nicolethemes.com/sapphire-html/products/dress2home.jpg",
"http://www.nicolethemes.com/sapphire-html/products/dress5home.jpg",
"http://www.nicolethemes.com/sapphire-html/products/dress6home.jpg",
],
price: 18,
company: "Bed",
info:
"Lorem ipsum .",
inCart: true,
count: 3,
total: 0
},
{
id: 2,
title: "Product 2",
images: [
"http://www.nicolethemes.com/sapphire-html/products/dress3home.jpg",
"http://www.nicolethemes.com/sapphire-html/products/dress7home.jpg"
],
price: 17,
company: "Sofa",
info:
"Lorem ipsum.",
inCart: true,
count: 5,
total: 0
}
]
const clear = () => {
let tempProduct = [...products]
let res = tempProduct.map(i => {return(
i.inCart = false,
i.count = 0)
});
};
Answer the question
In order to leave comments, you need to log in
special_price = div.find('span', attrs={'class' : 'subcategory-product-item__price_special'}).text
AttributeError: 'NoneType' object has no attribute 'text'
What if div.find doesn't find this string in principle (i.e. in the div in which the search takes place, it simply does not exist)?
You can do it like this, for example:
def safe_search(tag, attrs):
x = div.find('span', attrs={'class' : 'subcategory-product-item__price_special'})
if x is not None:
return x.text()
else:
return ''
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question