mercredi 7 novembre 2018

how to subtract Object value

can you tell me how to subtract the object value, let say that I have an Object for the item and has stock

 let theObj = {
    pants: [
       {
       color: "Pink",
       stock: 80,
       price: 30.99
       } 
           ]
    };

that is just not many values and keys, how about that Object has a lot of data?

for illustrations : if the user wants to buy the pant and after he/she pick what he/she wanted, that object will be subtracted by what user want to buy how many they want, and it will be subtracted if other users buy that pants and that colo until run out, I hope this makes sense

i hope my question and illustration make sense for you

let theObj = {
    pants: [
       {
       color: "Pink",
       stock: 80,
       price: 30.99
       } 
           ]
    };
    
const theData = theObj["pants"].map(e => e.stock - 1)
console.log(theData)
console.log(theObj) // nothing change when i subtact it 

Aucun commentaire:

Enregistrer un commentaire