Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
How I add new key on object

I have a code where i must add new key. The name is total. The properties total exist equal with quantity properties where the total is property quantity multiple with property price. In my code i use spread operator to get ...product and i want add key total and input to ...product. How i add key total ?

const axios = require("axios");

const url = "";
const getRequest = async (url) => {
  return (await axios.get(url)).data;
};
const result = async () => {
const carts = await getRequest("http://fakestoreapi.com/carts ");
const idProducts = await getRequest("http://fakestoreapi.com/products");


const merged = carts.map(cart => {
  return {
    ...cart,
    products: cart.products.map(product =>{
      return {
        ...product, 
//total : product.quantity * product.price,
        ...idProducts.find(item => product.productId === item.id)

      }
    })
  }
})
console.log(JSON.stringify(merged,null,2));
};
result();

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!