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

102
Views
Axios how to add property to array of objects

How can I add a userRating property of null to an array of objects using axios?

This is what I tried but it doesn't work

 const movieRequest = () => {
    axios
      .get(key)
      .then((response) => {
        const updatedResponse = response.data
        updatedResponse.map((movie) => ({
          ...movie,
          userRating: null,
        }))
        setMovieList(updatedResponse)
      })
      .catch((error) => console.log(error))
  }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

map returns a new array and does not mutate the array on which it is called. You just need to change your function to:

.then((response) => {
    const updatedResponse = response.data.map((movie) => ({
       ...movie,
       userRating: null,
    }));
    setMovieList(updatedResponse);
})
about 4 years ago · Juan Pablo Isaza Report

0

.map returns a new array, you need to assign it to a variable.

const mapped = updatedRespone.map.... setMovieList(mapped)

about 4 years ago · Juan Pablo Isaza Report
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!