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

230
Views
Add property & value from variable to existing object in JavaScript

I am trying to add properties & values from variable to existing object in JavaScript. My code is like below.

var partno = $this.parents('.cart_item').data('partno');
if (localStorage.getItem("shipping_values")) {
  var shipping_values = localStorage.getItem("shipping_values");
  shipping_values[partno] = $this.val();
  console.log(shipping_values); // I am not getting updated values here.
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Values received from localStorage are in strings. You should run JSON.parse and then add values to object.

var shipping_values = JSON.parse(localStorage.getItem("shipping_values"));
shipping_values[partno] = $this.val();

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!