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

194
Views
Expected token-error when inserting a variable into a string - Javascript
   var value = liste[eigenschaft];
   document.getElementById("demo6").innerHTML = value;
   var data = '{"products":[{"ingramPartNumber":"7U0169"}, {"ingramPartNumber":"6XH440"}]}';

I made a successful request for an API from one of our online-distributors. In the var data (as shown above) I can list the name/value-pairs (f.E.: ingramPartNumber and the actual partNumber) and I get back the corresponding data.

However, we want to make the call a bit more dynamic. We implemented a search and we want to have the value of the search (in the example above the var value) as an actual value in var data.

However, if I substitute the product-number with the variable (as shown below), it throws an error (expected token identifier) .. What am I missing?

   var value = liste[eigenschaft];
   document.getElementById("demo6").innerHTML = value;
   var data = '{"products":[{"ingramPartNumber":"7U0169"}, {"ingramPartNumber":"'value'"}]}';
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are doing this

   var data = '{"products":[{"ingramPartNumber":"7U0169"}, {"ingramPartNumber":"'value'"}]}';

Where you should be using interpolation or concatenation

   var data = '{"products":[{"ingramPartNumber":"7U0169"}, {"ingramPartNumber":' + value + '}]}';
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!